From: Daniel Galvez Date: Tue, 16 Oct 2012 18:59:36 +0000 (-0400) Subject: Fix #11280. IE6-8 need name attribute to parse param. Close gh-914. X-Git-Tag: 1.9.0b1~193 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ef7bce7e5c67f29a7e09ea1b0bb43b429fc9f59b;p=jquery.git Fix #11280. IE6-8 need name attribute to parse param. Close gh-914. --- diff --git a/AUTHORS.txt b/AUTHORS.txt index fc0305d4d..5a213d5a2 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -132,4 +132,5 @@ Elijah Manor Daniel Chatfield Nikita Govorov Michael Pennisi -Markus Staab \ No newline at end of file +Markus Staab +Daniel Gálvez \ No newline at end of file diff --git a/src/manipulation.js b/src/manipulation.js index aced4567b..672e9a147 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -39,7 +39,8 @@ var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figca _default: [ 0, "", "" ] }, safeFragment = createSafeFragment( document ), - fragmentDiv = safeFragment.appendChild( document.createElement("div") ); + fragmentDiv = safeFragment.appendChild( document.createElement("div") ), + addMandatoryAttributes = function( elem ) { return elem; }; wrapMap.optgroup = wrapMap.option; wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead; @@ -49,6 +50,23 @@ wrapMap.th = wrapMap.td; // unless wrapped in a div with non-breaking characters in front of it. if ( !jQuery.support.htmlSerialize ) { wrapMap._default = [ 1, "X
", "
" ]; + // Fixes #11280 + wrapMap.param = [ 1, "X", "" ]; + // Fixes #11280. HTMLParam name attribute added to avoid IE6-8 parsing issue. + addMandatoryAttributes = function( elem ) { + // If it's a param + return elem.replace(/]*)>/gi, function( m, s1, offset ) { + var name = s1.match( /name=["']([^"']*)["']/i ); + return name ? + ( name[1].length ? + // It has a name attr with a value + "" : + // It has name attr without a value + "" ) : + // No name attr + ""; + }); + }; } jQuery.fn.extend({ @@ -674,7 +692,7 @@ jQuery.extend({ tag = ( rtagName.exec( elem ) || ["", ""] )[1].toLowerCase(); wrap = wrapMap[ tag ] || wrapMap._default; depth = wrap[0]; - div.innerHTML = wrap[1] + elem + wrap[2]; + div.innerHTML = wrap[1] + addMandatoryAttributes( elem ) + wrap[2]; // Move to the right depth while ( depth-- ) { diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 669d52688..ca3a2ef40 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -469,6 +469,38 @@ test("append(Function)", function() { testAppend(manipulationFunctionReturningObj); }); +test("append(param) to object, see #11280", function() { + expect(11); + + var objectElement = document.createElement("object"), + $objectElement = jQuery( objectElement ), + paramElement = jQuery(""), + paramElement2 = jQuery(""), + paramElement3 = jQuery(""), + newObject = jQuery(""); + + equal( objectElement.childNodes.length, 0, "object did not have childNodes previously" ); + + document.body.appendChild( objectElement ); + + $objectElement.append( paramElement ); + equal( $objectElement.children().length, 1, "param single insertion ok" ); + equal( jQuery(objectElement.childNodes[0]).attr("type"), "wmode", "param.eq(0) has type=wmode" ); + + $objectElement.html( paramElement2 ); + equal( $objectElement.children().length, 1, "param single insertion ok" ); + equal( jQuery(objectElement.childNodes[0]).attr("type"), "wmode2", "param.eq(0) has type=wmode2" ); + + $objectElement.html( paramElement3 ); + equal( $objectElement.children().length, 1, "param single insertion ok" ); + equal( jQuery(objectElement.childNodes[0]).attr("name"), "foo", "param.eq(0) has name=foo" ); + + equal( newObject.children().length, 3, "param wrapper multiple insertion ok" ); + equal( newObject.children().eq(0).attr("type"), "foo", "param.eq(0) has type=foo" ); + equal( newObject.children().eq(1).attr("value"), "foo2", "param.eq(1) has value=foo2" ); + equal( newObject.children().eq(2).attr("name"), "bar", "param.eq(2) has name=bar" ); +}); + test("append(Function) with incoming value", function() { expect(12);