-
Notifications
You must be signed in to change notification settings - Fork 11
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 offset value when escape characters exist #48
Conversation
Hi @SebastienGllmt , This PR seems a duplicate of #24. Or at least related. Currently, the It's impossible for the library to know if you passed the string What you changed here simply counts all escaped chars as 2 bytes and all the unicode sequences as 6. What do you think? |
While this is true in general, you can see from the image I posted above that this doesn't matter for JSON specification purposes. \u is always followed by exactly 4 hexadecimal digits (so 6 total since it's prefixed with |
I don't think this matters. The two below are two totally separate and valid JSON strings. The escape is not done by Javascript - the escape is done by the JSON parser itself.
That is to say, the input to the parser are not both |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that you are right, but I have a few coding styles comments.
Once they are fixed, I'm happy to merge this.
Currently, the code assumes that 1 character in JSON corresponds to 1 character in the input. However, this isn't true because JSON supports escape characters (so multiple characters can map to a single JSON character)
This PR fixes it, and adds tests for this case