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(util): exportText treat text as template string #195

Merged
merged 1 commit into from
Feb 14, 2019

Conversation

azu
Copy link
Contributor

@azu azu commented Dec 30, 2018

escape text by jsesc.
jsesc support quote: "backtick".

fix #117

return `exports['${name}'] = \`${withNewLines}\`\n`
// jsesc replace "\n" with "\\n"
// https://github.com/mathiasbynens/jsesc/issues/20
const serialized = value.split('\n').map(line => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsesc does replace \\n with \n.

it('does escape template variable on the text', () => {
/* eslint-disable no-template-curly-in-string */
const formatted = exportText('name', '`${1}`')
const expected = "exports['name'] = `\n\\`\\${1}\\`\n`\n"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also test following code is work.

var exports = {};
eval("exports['name'] = `\n\\`\\${1}\\`\n`\n")

@azu azu force-pushed the fix-serialize-template-string branch from 9ffb7c7 to 7c404c5 Compare December 30, 2018 02:39
@azu
Copy link
Contributor Author

azu commented Dec 30, 2018

/cc @bahmutov @krzkaczor

@mike-north
Copy link

This PR looks good, it would be nice to see it merged, so I can strip out my workarounds.

@bahmutov
Copy link
Owner

🎉 This PR is included in version 7.1.13 🎉

The release is available on:

Your semantic-release bot 📦🚀

@azu azu deleted the fix-serialize-template-string branch February 14, 2019 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proper escaping for strings
3 participants