I am using MongoDB (via Amazon EC2) to serve data to my app - the problem I am having is if a particular word has - 's - in it, it causes major problems. Any idea how how I should be escaping these characters on the server end, while leaving the word with 's in tact on the front end?
What you probably want to do is to escape() your strings before you send them to the app. In JavaScript would use escape()/unescape() to encode and decode the values.
I’m assuming you’re sending a JSON response from your server, so this answer would be applicable to that. What is happening is that the JSON strings are enclosed by a tick ‘, and if your string has an apostrophe in it (’) it breaks the string:
{ 'myProperty': 'Todd's stuff' }
In that example, the string “Todd’s stuff” is terminated at the second apostrophe and the JSON becomes invalid because “s stuff” is not valid JSON.
If you’re not sending JSON, can you provide us your response data?
So here is what I am trying to do. I am trying to process a stripe charge, and keep getting this error:
STRIPE PLUGIN ERROR:
Stripe returned an error code. Here are the details Stripe provided:
HTTP status code: 400
message: Received unknown parameter: Rusty’s
type: invalid_request_error
param: Rusty’s
As you can see, if the word has an ’ in it, it gives me an error, otherwise the sale goes through fine. Stripe is grabbing the name from my mongoDB:
I’m just thinking out loud here, but your HTTP Status Code is 400 in that error. 4xx status codes are error codes returned by servers, so I get the feeling that this may be an error in your server code. Can you double check that?
Status code 400 is a specific error called “malformed request”. Basically the HTTP request coming in couldn’t be parsed into an endpoint and query key-value pairs (or the body was messed up on a POST request. Since Coronimum is used by many people, I’m pretty sure it’s creating valid requests. What’s left is the data the request is sending.
See this post on the problem. It doesn’t provide a Lua answer, but the code can be easily translated to our string.* library (or better use the UTF8 plugin if you’re going to have international characters).
Hi! So it’s definitely a problem with having " 's " in a word that I am trying to POST. I am trying to figure out how to escape the ’ to be able to send the word successfully. I am trying to use the UTF8 plugin, but not sure what function to use for this purpose? (I am not using international characters). If I were to use the php solution from that link you sent, can you perhaps please give me some guidance? Thanks!
The storeMenu[i].stripeName is being pulled from MongoDB, however Stripe does not like the 's and spits me back an error. If the name has no ‘s, then the transaction goes through fine. I can apply a find and replace to that I guess by doing the following: name = string.gsub( storeMenu[i].stripeName, "’", “/” )
What you probably want to do is to escape() your strings before you send them to the app. In JavaScript would use escape()/unescape() to encode and decode the values.
I’m assuming you’re sending a JSON response from your server, so this answer would be applicable to that. What is happening is that the JSON strings are enclosed by a tick ‘, and if your string has an apostrophe in it (’) it breaks the string:
{ 'myProperty': 'Todd's stuff' }
In that example, the string “Todd’s stuff” is terminated at the second apostrophe and the JSON becomes invalid because “s stuff” is not valid JSON.
If you’re not sending JSON, can you provide us your response data?
So here is what I am trying to do. I am trying to process a stripe charge, and keep getting this error:
STRIPE PLUGIN ERROR:
Stripe returned an error code. Here are the details Stripe provided:
HTTP status code: 400
message: Received unknown parameter: Rusty’s
type: invalid_request_error
param: Rusty’s
As you can see, if the word has an ’ in it, it gives me an error, otherwise the sale goes through fine. Stripe is grabbing the name from my mongoDB:
I’m just thinking out loud here, but your HTTP Status Code is 400 in that error. 4xx status codes are error codes returned by servers, so I get the feeling that this may be an error in your server code. Can you double check that?
Status code 400 is a specific error called “malformed request”. Basically the HTTP request coming in couldn’t be parsed into an endpoint and query key-value pairs (or the body was messed up on a POST request. Since Coronimum is used by many people, I’m pretty sure it’s creating valid requests. What’s left is the data the request is sending.
See this post on the problem. It doesn’t provide a Lua answer, but the code can be easily translated to our string.* library (or better use the UTF8 plugin if you’re going to have international characters).