diff options
author | Timmy Willison <timmywillisn@gmail.com> | 2016-01-07 16:50:26 -0500 |
---|---|---|
committer | Timmy Willison <timmywillisn@gmail.com> | 2016-01-07 16:50:59 -0500 |
commit | c1511c673148208ab17cafa0faf37bce3b4ae392 (patch) | |
tree | 39558a632bf0c13d004d16239bccfc874a26fd36 | |
parent | b9a695865b4eb3916f7320026d028a2866da6e4e (diff) | |
download | jquery-c1511c673148208ab17cafa0faf37bce3b4ae392.tar.gz jquery-c1511c673148208ab17cafa0faf37bce3b4ae392.zip |
Data: find hyphenated data with camelCased key
Fixes gh-2779
-rw-r--r-- | src/data.js | 7 | ||||
-rw-r--r-- | test/unit/data.js | 9 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/data.js b/src/data.js index f7734e7f3..b626fda45 100644 --- a/src/data.js +++ b/src/data.js @@ -123,7 +123,12 @@ jQuery.fn.extend( { // Attempt to get data from the cache // 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 ) { return data; } diff --git a/test/unit/data.js b/test/unit/data.js index 077362eda..00eb9b48e 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -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" ); +} ); |