From fbf829b7245f7d76ea02a44ab0a62427214b7575 Mon Sep 17 00:00:00 2001 From: Timmy Willison Date: Mon, 30 Nov 2015 11:30:31 -0500 Subject: [PATCH] Attributes: exclusively lowercase A-Z in attribute names Fixes gh-2730 Close gh-2749 --- src/attributes/attr.js | 11 +++++++++-- test/unit/attributes.js | 13 ++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/attributes/attr.js b/src/attributes/attr.js index ae48676d1..00b08489d 100644 --- a/src/attributes/attr.js +++ b/src/attributes/attr.js @@ -7,7 +7,14 @@ define( [ ], function( jQuery, access, support, rnotwhite ) { var boolHook, - attrHandle = jQuery.expr.attrHandle; + attrHandle = jQuery.expr.attrHandle, + + // Exclusively lowercase A-Z in attribute names (gh-2730) + // https://dom.spec.whatwg.org/#converted-to-ascii-lowercase + raz = /[A-Z]+/g, + lowercase = function( ch ) { + return ch.toLowerCase(); + }; jQuery.fn.extend( { attr: function( name, value ) { @@ -39,7 +46,7 @@ jQuery.extend( { // All attributes are lowercase // Grab necessary hook if one is defined if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) { - name = name.toLowerCase(); + name = name.replace( raz, lowercase ); hooks = jQuery.attrHooks[ name ] || ( jQuery.expr.match.bool.test( name ) ? boolHook : undefined ); } diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 9bf287688..cbf83d0ec 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -451,7 +451,9 @@ QUnit.test( "attr(String, Object)", function( assert ) { $radio = jQuery( "", { "value": "sup", - "type": "radio" + // Use uppercase here to ensure the type + // attrHook is still used + "TYPE": "radio" } ).appendTo( "#testForm" ); assert.equal( $radio.val(), "sup", "Value is not reset when type is set after value on a radio" ); @@ -472,6 +474,15 @@ QUnit.test( "attr(String, Object)", function( assert ) { assert.equal( jQuery( "#name" ).attr( "nonexisting", undefined ).attr( "nonexisting" ), undefined, ".attr('attribute', undefined) does not create attribute (#5571)" ); } ); +QUnit.test( "attr(non-ASCII)", function( assert ) { + assert.expect( 2 ); + + var $div = jQuery( "
" ).appendTo( "#qunit-fixture" ); + + assert.equal( $div.attr( "Ω" ), "omega", ".attr() exclusively lowercases characters in the range A-Z (gh-2730)" ); + assert.equal( $div.attr( "AØC" ), "alpha", ".attr() exclusively lowercases characters in the range A-Z (gh-2730)" ); +} ); + QUnit.test( "attr - extending the boolean attrHandle", function( assert ) { assert.expect( 1 ); var called = false, -- 2.39.5