Permalink
Browse files

Fix #11795, #10470: keep scripts in DOM; execute only on first insert…

…ion. Close gh-864.
  • Loading branch information...
gibson042 committed Nov 19, 2012
1 parent 90f9f49 commit e889134058232c5e19156353c5fc3bf3b4915a94
Showing with 372 additions and 265 deletions.
  1. +15 −9 src/core.js
  2. +196 −178 src/manipulation.js
  3. +161 −78 test/unit/manipulation.js
View
@@ -16,6 +16,7 @@ var
_$ = window.$,
// Save a reference to some core methods
+ core_concat = Array.prototype.concat,
core_push = Array.prototype.push,
core_slice = Array.prototype.slice,
core_indexOf = Array.prototype.indexOf,
@@ -472,26 +473,31 @@ jQuery.extend({
// data: string of html
// context (optional): If specified, the fragment will be created in this context, defaults to document
- // scripts (optional): If true, will include scripts passed in the html string
- parseHTML: function( data, context, scripts ) {
- var parsed;
+ // keepScripts (optional): If true, will include scripts passed in the html string
+ parseHTML: function( data, context, keepScripts ) {
if ( !data || typeof data !== "string" ) {
return null;
}
if ( typeof context === "boolean" ) {
- scripts = context;
- context = 0;
+ keepScripts = context;
+ context = false;
}
context = context || document;
+ var parsed = rsingleTag.exec( data ),
+ scripts = !keepScripts && [];
+
// Single tag
- if ( (parsed = rsingleTag.exec( data )) ) {
+ if ( parsed ) {
return [ context.createElement( parsed[1] ) ];
}
- parsed = jQuery.buildFragment( [ data ], context, scripts ? null : [] );
+ parsed = jQuery.buildFragment( [ data ], context, scripts );
+ if ( scripts ) {
+ jQuery( scripts ).remove();
+ }
return jQuery.merge( [],
- (parsed.cacheable ? jQuery.clone( parsed.fragment ) : parsed.fragment).childNodes );
+ ( parsed.cacheable ? jQuery.clone( parsed.fragment ) : parsed.fragment ).childNodes );
},
parseJSON: function( data ) {
@@ -744,7 +750,7 @@ jQuery.extend({
}
// Flatten any nested arrays
- return ret.concat.apply( [], ret );
+ return core_concat.apply( [], ret );
},
// A global GUID counter for objects
Oops, something went wrong.

3 comments on commit e889134

@Krinkle

This comment has been minimized.

Show comment Hide comment
@Krinkle

Krinkle Nov 19, 2012

Member

This introduced 4 test failures in the manipulation module in Safari 5.1.

Sample:

Check for appending an empty nodelist (Element)
Expected:   
"This link has class=\"blog\": Simon Willison's Weblog"
Result: 
"This link has class=\"blog\": Simon Willison's Weblog[object NodeList]"
Member

Krinkle replied Nov 19, 2012

This introduced 4 test failures in the manipulation module in Safari 5.1.

Sample:

Check for appending an empty nodelist (Element)
Expected:   
"This link has class=\"blog\": Simon Willison's Weblog"
Result: 
"This link has class=\"blog\": Simon Willison's Weblog[object NodeList]"
@boxed

This comment has been minimized.

Show comment Hide comment
@boxed

boxed May 13, 2013

This change also introduces failures with HtmlUnit. tmp.textContent = ""; blows up rather badly.

This change also introduces failures with HtmlUnit. tmp.textContent = ""; blows up rather badly.

@dmethvin

This comment has been minimized.

Show comment Hide comment
@dmethvin

dmethvin May 13, 2013

Member

@boxed If you want to file a bug report, please create a test case and use http://bugs.jquery.com.

Member

dmethvin replied May 13, 2013

@boxed If you want to file a bug report, please create a test case and use http://bugs.jquery.com.

Please sign in to comment.