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

Use jsesc instead of JSON.stringify to avoid JSON/HTML issues #207

Merged

Conversation

danmarcab
Copy link
Contributor

Fix for the issue: #206

As explained here: https://mathiasbynens.be/notes/etago

One can run into issues when trying to embed JSON containing HTML with <script> elements inside a <script> tag.

Switching to a utility with support for this fixes the issue: https://github.com/mathiasbynens/jsesc#isscriptcontext

I am not a JS expert by any means, no hard feelings if a better solution is found, this is the best I could do.

Hope it helps 👍 ,

Daniel

@dillonkearns dillonkearns merged commit f2d64df into dillonkearns:master Aug 25, 2021
@dillonkearns
Copy link
Owner

This is perfect 👍 Thank you so much for investigating and providing a fix!

@dillonkearns
Copy link
Owner

I added a test case to verify the fix and changed it so jsesc only runs within the pre-rendered HTML <script> (not for the content.json files since they aren't in an HTML context).

e26b361

@dillonkearns
Copy link
Owner

This is now live with NPM package version 2.1.8 🎉

https://github.com/dillonkearns/elm-pages/blob/master/CHANGELOG-NPM.md#218---2021-08-25

Thanks again for the PR! 🙏

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