Data: find hyphenated data with camelCased key

Fixes gh-2779
This commit is contained in:
Timmy Willison 2016-01-07 16:50:26 -05:00
parent b9a695865b
commit c1511c6731
2 changed files with 15 additions and 1 deletions

View File

@ -123,7 +123,12 @@ jQuery.fn.extend( {
// Attempt to get data from the cache // Attempt to get data from the cache
// with the key as-is // with the key as-is
data = dataUser.get( elem, key ); data = dataUser.get( elem, key ) ||
// Try to find dashed key if it exists (gh-2779)
// This is for 2.2.x only
dataUser.get( elem, key.replace( rmultiDash, "-$&" ).toLowerCase() );
if ( data !== undefined ) { if ( data !== undefined ) {
return data; return data;
} }

View File

@ -878,3 +878,12 @@ QUnit.test( ".data(prop) does not create expando", function( assert ) {
} }
} }
} ); } );
QUnit.test( ".data(camelCase) retrieves hyphenated keys", function( assert ) {
assert.expect( 1 );
var div = jQuery( "<div/>" );
$.data( div[ 0 ], "data-test", "data" );
assert.equal( div.data( "dataTest" ), "data" );
} );