Skip to content

Commit 153acc1

Browse files
committed
Attributes: exclusively lowercase A-Z in attribute names
Fixes jquerygh-2730
1 parent eaa3e9f commit 153acc1

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/attributes/attr.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ define( [
77
], function( jQuery, access, support, rnotwhite ) {
88

99
var boolHook,
10-
attrHandle = jQuery.expr.attrHandle;
10+
attrHandle = jQuery.expr.attrHandle,
11+
12+
// Exclusively lowercase A-Z in attribute names (gh-2730)
13+
// https://dom.spec.whatwg.org/#converted-to-ascii-lowercase
14+
raz = /[A-Z]/g,
15+
lowercase = function( ch ) {
16+
return ch.toLowerCase();
17+
};
1118

1219
jQuery.fn.extend( {
1320
attr: function( name, value ) {
@@ -39,7 +46,7 @@ jQuery.extend( {
3946
// All attributes are lowercase
4047
// Grab necessary hook if one is defined
4148
if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
42-
name = name.toLowerCase();
49+
name = name.replace( raz, lowercase );
4350
hooks = jQuery.attrHooks[ name ] ||
4451
( jQuery.expr.match.bool.test( name ) ? boolHook : undefined );
4552
}

test/unit/attributes.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ QUnit.test( "attr(String, Object)", function( assert ) {
451451

452452
$radio = jQuery( "<input>", {
453453
"value": "sup",
454-
"type": "radio"
454+
"TYPE": "radio"
455455
} ).appendTo( "#testForm" );
456456
assert.equal( $radio.val(), "sup", "Value is not reset when type is set after value on a radio" );
457457

@@ -472,6 +472,15 @@ QUnit.test( "attr(String, Object)", function( assert ) {
472472
assert.equal( jQuery( "#name" ).attr( "nonexisting", undefined ).attr( "nonexisting" ), undefined, ".attr('attribute', undefined) does not create attribute (#5571)" );
473473
} );
474474

475+
QUnit.test( "attr(non-ASCII)", function( assert ) {
476+
assert.expect( 2 );
477+
478+
var $div = jQuery( "<div Ω='omega' aØc='alpha'></div>" ).appendTo( "#qunit-fixture" );
479+
480+
assert.equal( $div.attr( "Ω" ), "omega", ".attr() exclusively lowercases characters in the range A-Z (gh-2730)" );
481+
assert.equal( $div.attr( "AØC" ), "alpha", ".attr() exclusively lowercases characters in the range A-Z (gh-2730)" );
482+
} );
483+
475484
QUnit.test( "attr - extending the boolean attrHandle", function( assert ) {
476485
assert.expect( 1 );
477486
var called = false,

0 commit comments

Comments
 (0)