From bb570fc37341520c27a76190e0c11271596890ec Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Tue, 20 Nov 2012 22:57:41 -0500 Subject: [PATCH] Fix #12920: remove addMandatoryAttributes. Close gh-1037. --- src/manipulation.js | 38 +++++++++----------------------------- test/unit/manipulation.js | 34 +++++++++------------------------- 2 files changed, 18 insertions(+), 54 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index c1097b20c..b179dab2e 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -32,44 +32,24 @@ var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figca wrapMap = { option: [ 1, "" ], legend: [ 1, "
", "
" ], + area: [ 1, "", "" ], + param: [ 1, "", "" ], thead: [ 1, "", "
" ], tr: [ 2, "", "
" ], - td: [ 3, "", "
" ], col: [ 2, "", "
" ], - area: [ 1, "", "" ], - _default: [ 0, "", "" ] + td: [ 3, "", "
" ], + + // IE6-8 can't serialize link, script, style, or any html5 (NoScope) tags, + // unless wrapped in a div with non-breaking characters in front of it. + _default: jQuery.support.htmlSerialize ? [ 0, "", "" ] : [ 1, "X
", "" ] }, safeFragment = createSafeFragment( document ), - fragmentDiv = safeFragment.appendChild( document.createElement("div") ), - addMandatoryAttributes = function( elem ) { return elem; }; + fragmentDiv = safeFragment.appendChild( document.createElement("div") ); wrapMap.optgroup = wrapMap.option; wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead; wrapMap.th = wrapMap.td; -// IE6-8 can't serialize link, script, style, or any html5 (NoScope) tags, -// 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({ text: function( value ) { return jQuery.access( this, function( value ) { @@ -733,7 +713,7 @@ jQuery.extend({ // Deserialize a standard representation tag = ( rtagName.exec( elem ) || ["", ""] )[1].toLowerCase(); wrap = wrapMap[ tag ] || wrapMap._default; - tmp.innerHTML = wrap[1] + addMandatoryAttributes( elem.replace( rxhtmlTag, "<$1>" ) ) + wrap[2]; + tmp.innerHTML = wrap[1] + elem.replace( rxhtmlTag, "<$1>" ) + wrap[2]; // Descend through wrappers to the right content j = wrap[0]; diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 8047bdf49..f08e7bd90 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -451,35 +451,19 @@ test("append(Function)", function() { }); 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 ); + expect( 5 ); - $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" ); + var object = jQuery( document.createElement("object") ).appendTo( document.body ); - $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" ); + equal( object.children().length, 0, "object does not start with children" ); - $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" ); + object.append( jQuery("") ); + equal( object.children().length, 1, "appended param" ); + equal( object.children().eq(0).attr("name"), "foo", "param 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" ); + object = jQuery(""); + equal( object.children().length, 1, "object created with child param" ); + equal( object.children().eq(0).attr("name"), "bar", "param has name=bar" ); }); test("append(Function) with incoming value", function() { -- 2.39.5