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

Handling invalid unicode escapes #192

Open
GULPF opened this issue Mar 4, 2019 · 3 comments
Open

Handling invalid unicode escapes #192

GULPF opened this issue Mar 4, 2019 · 3 comments

Comments

@GULPF
Copy link

GULPF commented Mar 4, 2019

Background: json5/json5-spec#12

JSON5.parse uses the ES6 behavior and accepts invalid Unicode sequences like "\uDEAD". However, this is not the case for the CLI. The CLI instead outputs U+FFFD (the replacement character). This probably happens because of Node trying to ensure that the output is valid UTF-8. I think it's best if these codepoints are escaped in the output, so that "\uDEAD" generates the escaped output "\uDEAD".

@jordanbtucker
Copy link
Member

I wasn't able to reproduce this issue. Can you please provide some code that demonstrates this?

@jordanbtucker jordanbtucker self-assigned this Mar 4, 2019
@GULPF
Copy link
Author

GULPF commented Mar 4, 2019

input.json5 contains "\uDEAD". After running json5 input.json5 -o output.json, output.json contains the following bytes (in hex): 22 EF BF BD 22, which is a string only containing the replacement character.

@jordanbtucker
Copy link
Member

Thanks for the example. That clarified the issue for me.

Your assumption about why this happens is correct. Since both JSON and JSON5 allow for invalid code unit sequences, the CLI should preserve them, however this would be a breaking change. The best approach may be to add a CLI flag in v2.2 that escapes invalid code point sequences. In v3.0 we can make that behavior the default and replace the CLI flag with one that replaces invalid code unit sequences with \uFFFD.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants