mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Attributes: exclusively lowercase A-Z in attribute names
Fixes gh-2730 Close gh-2749
This commit is contained in:
parent
6680c1b29e
commit
fbf829b724
@ -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 );
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user