This is related to but distinct from #333
The RewritingStream.emitText() method always calls escapeString on the text:
|
emitText({ text }) { |
|
this.push(escapeString(text, false)); |
|
} |
This causes it to break JavaScript. For example:
<script type="text/javascript">
(function() {
if ('PerformanceObserver' in window && 'PerformancePaintTiming' in window) {
// ...
ends up as
<script type="text/javascript">
(function() {
if ('PerformanceObserver' in window && 'PerformancePaintTiming' in window) {
// ...
and then the browser's JS parser chokes with a syntax error when it hits the &&.
It should probably do something similar to what _serializeTextNode does:
|
if ( |
|
parentTn === $.STYLE || |
|
parentTn === $.SCRIPT || |
|
parentTn === $.XMP || |
|
parentTn === $.IFRAME || |
|
parentTn === $.NOEMBED || |
|
parentTn === $.NOFRAMES || |
|
parentTn === $.PLAINTEXT || |
|
parentTn === $.NOSCRIPT |
|
) { |
|
this.html += content; |
|
} else { |
|
this.html += Serializer.escapeString(content, false); |
|
} |
(Or, whatever it ends up doing after the resolution of #333)
For a short-term workaround, I'm going to just call stream.push() stream.emitRaw() when inside of a <script> tag.
This is related to but distinct from #333
The
RewritingStream.emitText()method always calls escapeString on the text:parse5/packages/parse5-html-rewriting-stream/lib/index.js
Lines 79 to 81 in 9c683e1
This causes it to break JavaScript. For example:
ends up as
and then the browser's JS parser chokes with a syntax error when it hits the
&&.It should probably do something similar to what _serializeTextNode does:
parse5/packages/parse5/lib/serializer/index.js
Lines 136 to 149 in 9c683e1
(Or, whatever it ends up doing after the resolution of #333)
For a short-term workaround, I'm going to just call
stream.push()stream.emitRaw()when inside of a <script> tag.