Description
$.append fails when I try to append script element with HTML style comment.
There is no errors when I try to do the same thing using vanila JS:
var script = document.createElement('script');
script.text = '<!-- html style comment in javascript -->';
document.querySelector('html').append(script); // no errors
When I do it using jQuery:
var script = document.createElement('script');
script.text = '<!--html style comment in javascript -->';
$('html').append(script); // Uncaught SyntaxError: Unexpected identifier
The root cause:
The domManip function does RegExp replacement before calling DOMEval and removes <!-- and -->:
|
rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g; |
|
DOMEval( node.textContent.replace( rcleanScript, "" ), node, doc ); |
Link to test case
https://codepen.io/ovarn/pen/vYmgjzP (open browser console to see the error)
Description
$.append fails when I try to append script element with HTML style comment.
There is no errors when I try to do the same thing using vanila JS:
When I do it using jQuery:
The root cause:
The domManip function does RegExp replacement before calling DOMEval and removes <!-- and -->:
jquery/src/manipulation.js
Line 30 in a684e6b
jquery/src/manipulation.js
Line 164 in a684e6b
Link to test case
https://codepen.io/ovarn/pen/vYmgjzP (open browser console to see the error)