Skip to content

Commit

Permalink
Fix #11547. toLowerCase not work good on XML attributes.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dmethvin committed Jul 12, 2012
1 parent 0bde43a commit f4e5c17
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
9 changes: 2 additions & 7 deletions src/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion test/data/testinit.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var createDashboardXML = function() {
<dashboard> \
<locations class="foo"> \
<location for="bar" checked="different"> \
<infowindowtab> \
<infowindowtab normal="ab" mixedCase="yes"> \
<tab title="Location"><![CDATA[blabla]]></tab> \
<tab title="Users"><![CDATA[blublu]]></tab> \
</infowindowtab> \
Expand Down
40 changes: 26 additions & 14 deletions test/unit/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand All @@ -520,6 +520,31 @@ test("removeAttr(String)", function() {
} catch(e) {
ok( false, "Removing contenteditable threw an error (#10429)" );
}

$first = jQuery("<div Case='mixed'></div>");
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() {
Expand Down Expand Up @@ -1239,16 +1264,3 @@ test("coords returns correct values in IE6/IE7, see #10828", function() {
area = map.html("<area shape='rect' href='#' alt='a' /></map>").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 = "<root><item fooBar='123' /></root>",
$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" );
});

0 comments on commit f4e5c17

Please sign in to comment.