-
Notifications
You must be signed in to change notification settings - Fork 24
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 improper character escaping #21
Conversation
this will switch express-state to use json2. pertinent lines in json2: https://github.com/douglascrockford/JSON-js/blob/master/json2.js#L351
Could you explain in more detail why the built-in JSON.stringify is not sufficient? I want to understand an example of where someone would hit the escaping difference. Also, is there a related v8 bug or discussion for this? Thanks. |
we had user data where someone had used http://www.fileformat.info/info/unicode/char/2028/index.htm which is a line terminator, which is not a problem in json, but is in js. when the browser tries to parse the js it reads it as an unescaped newline in the middle of the json string. relevant blog post: http://timelessrepo.com/json-isnt-a-javascript-subset |
@norwood thanks for providing this info! I'll take a look and all this and evaluate whether we should simply escape the white space chars, or go the full route of using JSON2. |
@mathiasbynens your feedback on this issue and #22 would be much appreciated. Thanks! |
Yep, U+2028 and U+2029 are different in JavaScript vs. JSON. From a quick glance, the patch in #22 seems to account for those perfectly. Also note that you may want to use escape sequences for lone surrogates in JSON-formatted data. If raw lone surrogate ‘symbols’ are used in strings, JSON parsing/serialization still works fine, but it may cause issues when the serialized JSON data is then passed to a UTF-8 decoder. The second paragraph of the jsesc README mentions these problems: https://github.com/mathiasbynens/jsesc#readme To work around both of them, you could use |
@mathiasbynens thanks for your help! |
@norwood I've merged #22 (the alternate implantation that doesn't introduce a new dependency) and released |
awesome. thanks for the quick turnaround |
So you won’t be taking care of lone surrogates? Just wondering what the rationale is there. |
I will address those in another PR. I ran into issues with jsesc because of how this package needs to serialize values and revive those in the browser. I need to dig into it more, but didn't want that to hold this up. |
this will switch express-state to use json2.
pertinent lines in json2: https://github.com/douglascrockford/JSON-js/blob/master/json2.js#L351