tmedwards / tweego

Tweego is a free (gratis and libre) command line compiler for Twine/Twee story formats, written in Go.
https://www.motoslave.net/tweego
BSD 2-Clause "Simplified" License
124 stars 23 forks source link

"<</script>>" sequences in JS resources break browser HTML parser #46

Closed aimozg closed 1 year ago

aimozg commented 1 year ago

Describe the bug </script> character sequences that occur in JS resources break browser HTML parser, as they are treated as closing tags for <script role="script" id="twine-user-script" type="text/twine-javascript">, destroying any following content.

To Reproduce Compile a Tweego+SugarCube2 project with a JS file containing

Wikifier.wikifyEval("<<script>> console.log('It works!') <</script>>");

Desktop (please complete the following information):

Additional context I don't think it's even possible to escape these at Tweego level (see Restrictions for contents of script elements).

tmedwards commented 1 year ago

This is a browser issue, neither a Tweego nor a SugarCube issue.

Parsing of HTML <script> tag contents in the browser is probably not what most people expect/want due to historical issues that are never going to be changed. Thus, using the <<script>> macro within a <script> tag isn't going to work as you'd hope either.

That said. Why are you even attempting to use the <<script>> macro, which executes JavaScript, within your Story JavaScript, which exists to execute JavaScript?

(Closing this as not a Tweego issue, but feel free to continue the discussion until we get your situation straightened out.)

aimozg commented 1 year ago

This is a browser issue, neither a Tweego nor a SugarCube issue.

Tweego escapes <> in passages, and if it were possible to do same for </script> it should do it. But from what I understand, it is impossible (cannot escape token, only split, and that requires knowledge of JS context which is definitely not Tweego responsibility).

Still posted the issue in case you have ideas. The only I can think of is to emit a different tag than <script> with &-escaped characters, but that needs checking with the story format code and is an overkill for such an rare case.

That said. Why are you even attempting to use the < Githubissues.

  • Githubissues is a development platform for aggregating issues.