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 pretty-printing strings with \u2028 or \u2029 #1056

Merged
merged 2 commits into from
Feb 6, 2022

Conversation

djpohly
Copy link
Contributor

@djpohly djpohly commented Feb 4, 2022

These two characters are considered ordinary characters by JSON but line
terminators by ECMAScript (prior to ES2019). When pretty-printing a
string containing either character, JSON.stringify leaves it unescaped.
The result in recast.prettyPrint is that fromString, which follows
ECMAScript definitions, converts it mistakenly to a newline character.

Escaping these characters manually when the intent is to generate
ECMAScript (rather than JSON) eliminates the problem.

These two characters are considered ordinary characters by JSON but line
terminators by ECMAScript (prior to ES2019).  When pretty-printing a
string containing either character, JSON.stringify leaves it unescaped.
The result in recast.prettyPrint is that fromString, which follows
ECMAScript definitions, converts it mistakenly to a newline character.

Escaping these characters manually when the intent is to generate
ECMAScript (rather than JSON) eliminates the problem.
@eventualbuddha eventualbuddha merged commit cb7ff9a into benjamn:master Feb 6, 2022
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