From f4e5c1729a2efe6086ac2407f82e928b26991f83 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Wed, 11 Jul 2012 22:46:34 -0400 Subject: [PATCH] Fix #11547. toLowerCase not work good on XML attributes. This was fixed to some extent in gh-724 but there were insufficient test cases. Removing the lowercase completely allows IE 6/7 to work properly since there you need an exact case match for attributes, even in HTML docs. More discussion and test cases in the comments on gh-724. --- src/attributes.js | 9 ++------- test/data/testinit.js | 2 +- test/unit/attributes.js | 40 ++++++++++++++++++++++++++-------------- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/attributes.js b/src/attributes.js index 879064b2a..c3890c459 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -338,19 +338,14 @@ jQuery.extend({ }, removeAttr: function( elem, value ) { - var propName, attrNames, name, l, isBool, + var propName, attrNames, name, isBool, i = 0; if ( value && elem.nodeType === 1 ) { - if ( !jQuery.isXMLDoc( elem ) ) { - value = value.toLowerCase(); - } - attrNames = value.split( core_rspace ); - l = attrNames.length; - for ( ; i < l; i++ ) { + for ( ; i < attrNames.length; i++ ) { name = attrNames[ i ]; if ( name ) { diff --git a/test/data/testinit.js b/test/data/testinit.js index 7d340acee..18f9e2845 100644 --- a/test/data/testinit.js +++ b/test/data/testinit.js @@ -58,7 +58,7 @@ var createDashboardXML = function() { \ \ \ - \ + \ \ \ \ diff --git a/test/unit/attributes.js b/test/unit/attributes.js index d5477b627..07608b4bd 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -496,7 +496,7 @@ test("attr('tabindex', value)", function() { }); test("removeAttr(String)", function() { - expect( 10 ); + expect( 12 ); var $first; equal( jQuery("#mark").removeAttr( "class" ).attr("class"), undefined, "remove class" ); @@ -520,6 +520,31 @@ test("removeAttr(String)", function() { } catch(e) { ok( false, "Removing contenteditable threw an error (#10429)" ); } + + $first = jQuery("
"); + equal( $first.attr("Case"), "mixed", "case of attribute doesn't matter" ); + $first.removeAttr("Case"); + // IE 6/7 return empty string here, not undefined + ok( !$first.attr("Case"), "mixed-case attribute was removed" ); +}); + +test("removeAttr(String) in XML", function() { + expect( 7 ); + var xml = createDashboardXML(), + iwt = jQuery( "infowindowtab", xml ); + + equal( iwt.attr("normal"), "ab", "Check initial value" ); + iwt.removeAttr("Normal"); + equal( iwt.attr("normal"), "ab", "Should still be there" ); + iwt.removeAttr("normal"); + equal( iwt.attr("normal"), undefined, "Removed" ); + + equal( iwt.attr("mixedCase"), "yes", "Check initial value" ); + equal( iwt.attr("mixedcase"), undefined, "toLowerCase not work good" ); + iwt.removeAttr("mixedcase"); + equal( iwt.attr("mixedCase"), "yes", "Should still be there" ); + iwt.removeAttr("mixedCase"); + equal( iwt.attr("mixedCase"), undefined, "Removed" ); }); test("removeAttr(Multi String, variable space width)", function() { @@ -1239,16 +1264,3 @@ test("coords returns correct values in IE6/IE7, see #10828", function() { area = map.html("a").find("area"); equal( area.attr("coords"), undefined, "did not retrieve coords correctly"); }); - -test("Handle cased attributes on XML DOM correctly in removeAttr()", function() { - expect(1); - - var xmlStr = "", - $xmlDoc = jQuery( jQuery.parseXML( xmlStr ) ), - $item = $xmlDoc.find( "item" ), - el = $item[0]; - - $item.removeAttr( "fooBar" ); - - equal( el.attributes.length, 0, "attribute with upper case did not get removed" ); -}); -- 2.39.5