Attributes: exclusively lowercase A-Z in attribute names

Fixes gh-2730
Close gh-2749
This commit is contained in:
Timmy Willison 2015-11-30 11:30:31 -05:00
parent 6680c1b29e
commit fbf829b724
2 changed files with 21 additions and 3 deletions

View File

@ -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 File

@ -451,7 +451,9 @@ QUnit.test( "attr(String, Object)", function( assert ) {
$radio = jQuery( "<input>", {
"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( "<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,