mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
Fixes #13850. Better removal of hyphenated data property names.
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
This commit is contained in:
parent
e8b110c646
commit
2406b5e290
@ -142,7 +142,7 @@ Data.prototype = {
|
|||||||
return value !== undefined ? value : key;
|
return value !== undefined ? value : key;
|
||||||
},
|
},
|
||||||
remove: function( owner, key ) {
|
remove: function( owner, key ) {
|
||||||
var i, name,
|
var i, name, camel,
|
||||||
unlock = this.key( owner ),
|
unlock = this.key( owner ),
|
||||||
cache = this.cache[ unlock ];
|
cache = this.cache[ unlock ];
|
||||||
|
|
||||||
@ -160,13 +160,14 @@ Data.prototype = {
|
|||||||
// This will only penalize the array argument path.
|
// This will only penalize the array argument path.
|
||||||
name = key.concat( key.map( jQuery.camelCase ) );
|
name = key.concat( key.map( jQuery.camelCase ) );
|
||||||
} else {
|
} else {
|
||||||
|
camel = jQuery.camelCase( key );
|
||||||
// Try the string as a key before any manipulation
|
// Try the string as a key before any manipulation
|
||||||
if ( key in cache ) {
|
if ( key in cache ) {
|
||||||
name = [ key ];
|
name = [ key, camel ];
|
||||||
} else {
|
} else {
|
||||||
// If a key with the spaces exists, use it.
|
// If a key with the spaces exists, use it.
|
||||||
// Otherwise, create an array by matching non-whitespace
|
// Otherwise, create an array by matching non-whitespace
|
||||||
name = jQuery.camelCase( key );
|
name = camel;
|
||||||
name = name in cache ?
|
name = name in cache ?
|
||||||
[ name ] : ( name.match( core_rnotwhite ) || [] );
|
[ name ] : ( name.match( core_rnotwhite ) || [] );
|
||||||
}
|
}
|
||||||
|
@ -613,6 +613,35 @@ test(".data supports interoperable removal of hyphenated/camelCase properties",
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test(".data supports interoperable removal of properties SET TWICE #13850", function() {
|
||||||
|
var div = jQuery("<div>").appendTo("#qunit-fixture"),
|
||||||
|
datas = {
|
||||||
|
"non-empty": "a string",
|
||||||
|
"empty-string": "",
|
||||||
|
"one-value": 1,
|
||||||
|
"zero-value": 0,
|
||||||
|
"an-array": [],
|
||||||
|
"an-object": {},
|
||||||
|
"bool-true": true,
|
||||||
|
"bool-false": false,
|
||||||
|
// JSHint enforces double quotes,
|
||||||
|
// but JSON strings need double quotes to parse
|
||||||
|
// so we need escaped double quotes here
|
||||||
|
"some-json": "{ \"foo\": \"bar\" }"
|
||||||
|
};
|
||||||
|
|
||||||
|
expect( 9 );
|
||||||
|
|
||||||
|
jQuery.each( datas, function( key, val ) {
|
||||||
|
div.data( key, val );
|
||||||
|
div.data( key, val );
|
||||||
|
|
||||||
|
div.removeData( key );
|
||||||
|
|
||||||
|
equal( div.data( key ), undefined, "removal: " + key );
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test( ".removeData supports removal of hyphenated properties via array (#12786)", function() {
|
test( ".removeData supports removal of hyphenated properties via array (#12786)", function() {
|
||||||
expect( 4 );
|
expect( 4 );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user