Made JSON.stringify comptible with javascript JSON#266
Merged
Conversation
The current JSON.stringify method escaped characters in a way that was NOT compatible with the current javascript JSON implementation. For example, the string single-character "\n" was being translated into: "\"\ \"" Instead of being stringifyed as: "\"\n\"". This is because the character \n was being added, instead of adding an "n" preceeded by an "\\". This commit fixes such problem by using a direct mapping from escapable characters into their escaped stringified version.
willemneal
suggested changes
Jul 26, 2021
Contributor
willemneal
left a comment
There was a problem hiding this comment.
Good catch! Just my two comments!
MaxGraey
reviewed
Jul 28, 2021
Co-authored-by: Max Graey <maxgraey@gmail.com>
willemneal
reviewed
Jul 29, 2021
willemneal
reviewed
Jul 29, 2021
willemneal
suggested changes
Jul 29, 2021
| } | ||
| escaped.push(charCode); | ||
| const char = this._str.at(i); | ||
| escaped[i] = this.escapeChar(char); |
Contributor
There was a problem hiding this comment.
Also this shouldn't be an instance method since we don't access this inside of it and we have to pass the reference every time.
Contributor
Author
There was a problem hiding this comment.
Moved it outside the class
willemneal
reviewed
Jul 29, 2021
Contributor
Author
|
@willemneal do you think this is ready now? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The current JSON.stringify method escaped characters in a way that
was NOT compatible with the current javascript JSON implementation.
For example, the string single-character "\n" was being translated
into:
Instead of being stringifyed as:
"\"\n\"". This is because thecharacter \n was being added, instead of adding an "n" preceeded
by an "\".
This commit fixes such problem by using a direct mapping from
escapable characters into their escaped stringified version.