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 string escapes #2

Merged
merged 3 commits into from
Jan 21, 2018
Merged

Fix string escapes #2

merged 3 commits into from
Jan 21, 2018

Conversation

kevcenteno
Copy link
Owner

Merges zaach#54

ntdaley and others added 3 commits October 14, 2014 21:27
Previously the different escape characters were being applied one after the other, so that "\\n" in the json will get turned into a new-line instead of "\n".
Previously unicode escapes were not being converted resulting in stringifying the parse result turning "\u20AC" getting turned into "\\u20AC".
Previously "\/" was not being converted resulting in stringifying the parse result turning it into "\\/"

Note: I removed handling of '\v' because this would not be accepted by the lexer anyway, and is not part of the json standard.
Note: Because unicode escapes are converted, strings in the input like "\u20AC" will become their unicode equivalent after parsing (e.g. in this case the euro character).

Also changed the command line use of JSON.stringify to further process the result to convert non-ASCII printable characters to unicode escapes.  While not strictly necessary according to the JSON standard, ascii output is safer for some parsers, and now that the parser processes unicode escapes there is more chance of having non-ASCII characters in the parser output.
I would suggest that it would be better to always use formatter.js instead of JSON.stringify, because that way the choice between unicode escaped values and unicode characters would always be the same for input and output.  Similar formatting changes should probably be made in the web version.
@kevcenteno kevcenteno merged commit 751caca into master Jan 21, 2018
@kevcenteno kevcenteno deleted the fix-string-escapes branch January 21, 2018 01:14
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