Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error on JSON request with certain unicode chars #6

Merged
merged 2 commits into from
Oct 8, 2017
Merged

Fix error on JSON request with certain unicode chars #6

merged 2 commits into from
Oct 8, 2017

Conversation

colxi
Copy link
Contributor

@colxi colxi commented Jul 31, 2017

When any of the values represented inside the Object being stringified, contain some UNICODE characters, produces the return of the following Error:
{message : "Invalid request body - JSON parse error", type : "invalid_json"}

The proposed patch, converts each string char to its (Hex) Unicode representation
An example, using a Spanish word -with a conflictive accent mark in the 'o'- :
"Atención" => "\u0041\u0074\u0065\u006e\u0063\u0069\u00f3\u006e"
The proposed disambiguation prevents the unexpected error on the request sending.

(addition in line 44 of databox.js)
jsonData = jsonData.replace(/[\u007F-\uFFFF]/g, function(chr) {
return "\u" + ("0000" + chr.charCodeAt(0).toString(16)).substr(-4);
});

When any of the values represented inside the Object being stringified, contain some UNICODE characters, produces the return of the following Error: 
{message : "Invalid request body - JSON parse error", type : "invalid_json"}

The proposed patch, converts each string char to its (Hex) Unicode representation  
An example, using a Spanish word -with a conflictive accent mark in the 'o'- :
"Atención" => "\u0041\u0074\u0065\u006e\u0063\u0069\u00f3\u006e"
The proposed disambiguation prevents the unexpected error on the request sending.
@colxi
Copy link
Contributor Author

colxi commented Aug 1, 2017

I updated my fix, with a better approach, where the explicit UTF-8 encoding is only applied to the value of the attributes.
However i consider , the whole JSON request should be encoded with UTF-8, according to the internationalization standards, it should be done using lower level mechanisms, not via scripting.

Issue : #7

@colxi
Copy link
Contributor Author

colxi commented Sep 13, 2017

No movement arround this?

@VladaPetrovic
Copy link
Member

Sorry I haven't had much time for this. I'll definitely have more time this week to look into it.

@VladaPetrovic VladaPetrovic merged commit d8d8feb into databox:master Oct 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants