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

'Allow newlines' option #20

Closed
cohix opened this issue Feb 15, 2015 · 4 comments
Closed

'Allow newlines' option #20

cohix opened this issue Feb 15, 2015 · 4 comments

Comments

@cohix
Copy link

cohix commented Feb 15, 2015

jsesc should have an option to allow newline characters:

var escaped = jsesc(string, {newlinesAllowed: true} );

So if the string contains a newline character (\n), it would not be replaced by \\n

@mathiasbynens
Copy link
Owner

What’s your use case exactly?

@cohix
Copy link
Author

cohix commented Feb 15, 2015

I have a field in my database that I want to allow real newline characters.

@mathiasbynens
Copy link
Owner

For now this can be solved with:

var escaped = string.split('\n').map(function(line) {
  return jsesc(line);
}).join('\n');

I’m worried that this is not common enough to extend the API for. Also, allowNewlines seems like too specific an option. If we decide to add something like this, maybe add a whitelist property instead?

@cohix
Copy link
Author

cohix commented Feb 17, 2015

Yeah I like the whitelist idea. Good call.

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