Skip to content

Commit

Permalink
Landing pull request 550. IE6,7,8 cannot use cached fragments from un…
Browse files Browse the repository at this point in the history
…known elems. Fixes #10501.

More Details:
- #550
- http://bugs.jquery.com/ticket/10501
  • Loading branch information
timmywil committed Oct 23, 2011
1 parent 516f3cd commit f3a4d26
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
30 changes: 17 additions & 13 deletions src/manipulation.js
@@ -1,30 +1,30 @@
(function( jQuery ) { (function( jQuery ) {


function createSafeFragment( document ) { function createSafeFragment( document ) {
var nodeNames = ( var list = nodeNames.split( " " ),
"abbr article aside audio canvas datalist details figcaption figure footer " +
"header hgroup mark meter nav output progress section summary time video"
).split( " " ),
safeFrag = document.createDocumentFragment(); safeFrag = document.createDocumentFragment();


if ( safeFrag.createElement ) { if ( safeFrag.createElement ) {
while ( nodeNames.length ) { while ( list.length ) {
safeFrag.createElement( safeFrag.createElement(
nodeNames.pop() list.pop()
); );
} }
} }
return safeFrag; return safeFrag;
} }


var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g, var nodeNames = "abbr article aside audio canvas datalist details figcaption figure footer " +
"header hgroup mark meter nav output progress section summary time video",
rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
rleadingWhitespace = /^\s+/, rleadingWhitespace = /^\s+/,
rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig, rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,
rtagName = /<([\w:]+)/, rtagName = /<([\w:]+)/,
rtbody = /<tbody/i, rtbody = /<tbody/i,
rhtml = /<|&#?\w+;/, rhtml = /<|&#?\w+;/,
rnoInnerhtml = /<(?:script|style)/i, rnoInnerhtml = /<(?:script|style)/i,
rnocache = /<(?:script|object|embed|option|style)/i, rnocache = /<(?:script|object|embed|option|style)/i,
rnoshimcache = new RegExp("<(?:" + nodeNames.replace(" ", "|") + ")", "i"),
// 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,
Expand Down Expand Up @@ -456,7 +456,8 @@ function cloneFixAttributes( src, dest ) {
} }


jQuery.buildFragment = function( args, nodes, scripts ) { jQuery.buildFragment = function( args, nodes, scripts ) {
var fragment, cacheable, cacheresults, doc; var fragment, cacheable, cacheresults, doc,
first = args[ 0 ];


// nodes may contain either an explicit document object, // nodes may contain either an explicit document object,
// a jQuery collection or context object. // a jQuery collection or context object.
Expand All @@ -476,12 +477,15 @@ jQuery.buildFragment = function( args, nodes, scripts ) {
// Cloning options loses the selected state, so don't cache them // Cloning options loses the selected state, so don't cache them
// IE 6 doesn't like it when you put <object> or <embed> elements in a fragment // IE 6 doesn't like it when you put <object> or <embed> elements in a fragment
// Also, WebKit does not clone 'checked' attributes on cloneNode, so don't cache // Also, WebKit does not clone 'checked' attributes on cloneNode, so don't cache
if ( args.length === 1 && typeof args[0] === "string" && args[0].length < 512 && doc === document && // Lastly, IE6,7,8 will not correctly reuse cached fragments that were created from unknown elems #10501
args[0].charAt(0) === "<" && !rnocache.test( args[0] ) && (jQuery.support.checkClone || !rchecked.test( args[0] )) ) { if ( args.length === 1 && typeof first === "string" && first.length < 512 && doc === document &&
first.charAt(0) === "<" && !rnocache.test( first ) &&
(jQuery.support.checkClone || !rchecked.test( first )) &&
(!jQuery.support.unknownElems && rnoshimcache.test( first )) ) {


cacheable = true; cacheable = true;


cacheresults = jQuery.fragments[ args[0] ]; cacheresults = jQuery.fragments[ first ];
if ( cacheresults && cacheresults !== 1 ) { if ( cacheresults && cacheresults !== 1 ) {
fragment = cacheresults; fragment = cacheresults;
} }
Expand All @@ -493,7 +497,7 @@ jQuery.buildFragment = function( args, nodes, scripts ) {
} }


if ( cacheable ) { if ( cacheable ) {
jQuery.fragments[ args[0] ] = cacheresults ? fragment : 1; jQuery.fragments[ first ] = cacheresults ? fragment : 1;
} }


return { fragment: fragment, cacheable: cacheable }; return { fragment: fragment, cacheable: cacheable };
Expand Down Expand Up @@ -735,7 +739,7 @@ jQuery.extend({
}, },


cleanData: function( elems ) { cleanData: function( elems ) {
var data, id, var data, id,
cache = jQuery.cache, cache = jQuery.cache,
special = jQuery.event.special, special = jQuery.event.special,
deleteExpando = jQuery.support.deleteExpando; deleteExpando = jQuery.support.deleteExpando;
Expand Down
3 changes: 3 additions & 0 deletions test/data/testsuite.css
Expand Up @@ -123,3 +123,6 @@ body, div { background: url(http://static.jquery.com/files/rocker/images/logo_jq


/* #6652 REMOVE FILTER:ALPHA(OPACITY=100) AFTER ANIMATION */ /* #6652 REMOVE FILTER:ALPHA(OPACITY=100) AFTER ANIMATION */
#t6652 div { filter: alpha(opacity=50); } #t6652 div { filter: alpha(opacity=50); }

/* #10501 */
section { background:#f0f; display:block; }
14 changes: 12 additions & 2 deletions test/unit/manipulation.js
Expand Up @@ -472,8 +472,18 @@ test("append HTML5 sectioning elements (Bug #6485)", function () {
var article = jQuery("article"), var article = jQuery("article"),
aside = jQuery("aside"); aside = jQuery("aside");


equal( article.css("fontSize"), "10px", 'HTML5 elements are styleable'); equal( article.css("fontSize"), "10px", "HTML5 elements are styleable");
equal( aside.length, 1, 'HTML5 elements do not collapse their children') equal( aside.length, 1, "HTML5 elements do not collapse their children")
});

test("HTML5 Elements inherit styles from style rules (Bug #10501)", function () {
expect(1);

jQuery("#qunit-fixture").append("<article id='article'></article>");
jQuery("#article").append("<section>This section should have a pink background.</section>");

// In IE, the missing background color will claim its value is "transparent"
notEqual( jQuery("section").css("background-color"), "transparent", "HTML5 elements inherit styles");
}); });


test("clone() (#6485)", function () { test("clone() (#6485)", function () {
Expand Down

0 comments on commit f3a4d26

Please sign in to comment.