-
Notifications
You must be signed in to change notification settings - Fork 20.5k
Closed
Description
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 -->:
Line 30 in a684e6b
| rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g; |
Line 164 in a684e6b
| DOMEval( node.textContent.replace( rcleanScript, "" ), node, doc ); |
Link to test case
https://codepen.io/ovarn/pen/vYmgjzP (open browser console to see the error)