Skip to content

Commit c1511c6

Browse files
committed
Data: find hyphenated data with camelCased key
Fixes gh-2779
1 parent b9a6958 commit c1511c6

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/data.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,12 @@ jQuery.fn.extend( {
123123

124124
// Attempt to get data from the cache
125125
// with the key as-is
126-
data = dataUser.get( elem, key );
126+
data = dataUser.get( elem, key ) ||
127+
128+
// Try to find dashed key if it exists (gh-2779)
129+
// This is for 2.2.x only
130+
dataUser.get( elem, key.replace( rmultiDash, "-$&" ).toLowerCase() );
131+
127132
if ( data !== undefined ) {
128133
return data;
129134
}

test/unit/data.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,3 +878,12 @@ QUnit.test( ".data(prop) does not create expando", function( assert ) {
878878
}
879879
}
880880
} );
881+
882+
QUnit.test( ".data(camelCase) retrieves hyphenated keys", function( assert ) {
883+
assert.expect( 1 );
884+
885+
var div = jQuery( "<div/>" );
886+
887+
$.data( div[ 0 ], "data-test", "data" );
888+
assert.equal( div.data( "dataTest" ), "data" );
889+
} );

0 commit comments

Comments
 (0)