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

Special characters are not escaped correctly #70

Open
DanielSWolf opened this issue Dec 16, 2020 · 1 comment
Open

Special characters are not escaped correctly #70

DanielSWolf opened this issue Dec 16, 2020 · 1 comment

Comments

@DanielSWolf
Copy link

I believe that stringify-object doesn't correctly escape special characters in strings. Consider the following program:

const stringifyObject = require('stringify-object');

const s = 'tab: \t newline: \n backslash: \\';
console.log(JSON.stringify(s));     // Output: "tab: \t newline: \n backslash: \\"
console.log(stringifyObject(s));    // Output: 'tab: 	 newline: \n backslash: \'

I'd expect stringifyObject() to give results similar to JSON.stringify(), in that both should return a valid JavaScript expression. However, both the tab character and the backslash are not escaped, but are copied to the output verbatim.

In the case of the tab character, the resulting code is unexpected but still technically correct.

In the case of the backslash, the resulting code is no valid JavaScript any more, but leaves an unterminated string.

Only the newline character is escaped as expected.

@cpiber
Copy link
Contributor

cpiber commented Feb 14, 2022

Currently, only \r and \n are escaped. #72 at least fixes backslashes.

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

No branches or pull requests

2 participants