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

Missing <script>s on test page #109

Merged
merged 2 commits into from
May 20, 2016

Conversation

wardpeet
Copy link
Contributor

@wardpeet wardpeet commented May 14, 2016

Code with comments break, not sure how to fix this
should fix #85

var jsesc = require('jsesc');

module.exports = (value) => jsesc(
value.replace(/[\r\n]{1,2}/g, '')
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the .replace needed?

Copy link
Contributor

Choose a reason for hiding this comment

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

My original idea was to use jsesc(value, { wrap: true }) so it returns a string literal including the quotes.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this needs .replace(/<\/script/g, '<\\/script>') since the output is placed inside a <script> in HTML.

My earlier question remains, though: why .replace(/[\r\n]{1,2}/g, ')'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're correct, problem is that i thought jsesc was doing weird escaping but it was handlebars. I will push new commits later today.

@wardpeet
Copy link
Contributor Author

Updated :) Let me know if it's okay :)

@@ -29,7 +29,31 @@
</footer>

{{#if benchmark}}
<script src="/test.js"></script>
<script src="/test.js"></script> <script src="/test.js"></script>
Copy link
Member

Choose a reason for hiding this comment

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

just need this once, right?

@mathiasbynens
Copy link
Contributor

I think we’re almost there! Left some comments.

{
wrap: true
}
).replace(/<\/script/g, '<\\/script>');
Copy link
Contributor

Choose a reason for hiding this comment

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

Let’s update jsesc to v1.1.0 and use escapeEtago: true instead of doing the .replace ourselves. 👍

@wardpeet
Copy link
Contributor Author

My tests didn't work so i didn't see some issues. But now they are fixed . I updated everything said above :) hopefully I finally got it right :p

@mathiasbynens
Copy link
Contributor

LGTM! Thanks, @wardpeet!

@mathiasbynens mathiasbynens merged commit a0c7648 into jsperf:master May 20, 2016
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.

Missing <script>s on test page
3 participants