Permalink
Browse files

Attributes: exclusively lowercase A-Z in attribute names

Fixes gh-2730
  • Loading branch information...
timmywil committed Nov 30, 2015
1 parent eaa3e9f commit 153acc1338073f1047b906fff8c9d1b9522c33bf
Showing with 19 additions and 3 deletions.
  1. +9 −2 src/attributes/attr.js
  2. +10 −1 test/unit/attributes.js
View
@@ -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 );
}
View
@@ -451,7 +451,7 @@ QUnit.test( "attr(String, Object)", function( assert ) {
$radio = jQuery( "<input>", {
"value": "sup",
"type": "radio"
"TYPE": "radio"
} ).appendTo( "#testForm" );
assert.equal( $radio.val(), "sup", "Value is not reset when type is set after value on a radio" );
@@ -472,6 +472,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( "<div Ω='omega' aØc='alpha'></div>" ).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,

0 comments on commit 153acc1

Please sign in to comment.