Commit 391398cf authored by jaubourg's avatar jaubourg

Fixes #9221. Wraps openings of html comments and CDATA blocks found at the...

Fixes #9221. Wraps openings of html comments and CDATA blocks found at the beginning of inserted script elements into a javascript block comment so that the new implementation of globalEval will not throw an exception in IE (execScript being less lenient than eval). Unit tests added.
parent 3a1c27b5
...@@ -10,6 +10,7 @@ var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g, ...@@ -10,6 +10,7 @@ var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
// checked="checked" or checked // checked="checked" or checked
rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i, rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
rscriptType = /\/(java|ecma)script/i, rscriptType = /\/(java|ecma)script/i,
rcleanScript = /^\s*<!(?:\[CDATA\[|\-\-)/,
wrapMap = { wrapMap = {
option: [ 1, "<select multiple='multiple'>", "</select>" ], option: [ 1, "<select multiple='multiple'>", "</select>" ],
legend: [ 1, "<fieldset>", "</fieldset>" ], legend: [ 1, "<fieldset>", "</fieldset>" ],
...@@ -738,7 +739,7 @@ function evalScript( i, elem ) { ...@@ -738,7 +739,7 @@ function evalScript( i, elem ) {
dataType: "script" dataType: "script"
}); });
} else { } else {
jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" ); jQuery.globalEval( ( elem.text || elem.textContent || elem.innerHTML || "" ).replace( rcleanScript, "/*$0*/" ) );
} }
if ( elem.parentNode ) { if ( elem.parentNode ) {
......
...@@ -1396,3 +1396,21 @@ test("jQuery.buildFragment - no plain-text caching (Bug #6779)", function() { ...@@ -1396,3 +1396,21 @@ test("jQuery.buildFragment - no plain-text caching (Bug #6779)", function() {
equals($f.text(), bad.join(""), "Cached strings that match Object properties"); equals($f.text(), bad.join(""), "Cached strings that match Object properties");
$f.remove(); $f.remove();
}); });
test( "jQuery.html - execute scripts escaped with html comment or CDATA (#9221)", function() {
expect( 2 );
jQuery( [
'<script type="text/javascript">',
'<!--',
'ok( true, "<!-- handled" );',
'//-->',
'</script>'
].join ( "\n" ) ).appendTo( "#qunit-fixture" );
jQuery( [
'<script type="text/javascript">',
'<![CDATA[',
'ok( true, "<![CDATA[ handled" );',
'//]]>',
'</script>'
].join ( "\n" ) ).appendTo( "#qunit-fixture" );
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment