]> source.dussan.org Git - jquery.git/commitdiff
Data: find hyphenated data with camelCased key
authorTimmy Willison <timmywillisn@gmail.com>
Thu, 7 Jan 2016 21:50:26 +0000 (16:50 -0500)
committerTimmy Willison <timmywillisn@gmail.com>
Thu, 7 Jan 2016 21:50:59 +0000 (16:50 -0500)
Fixes gh-2779

src/data.js
test/unit/data.js

index f7734e7f38b52186fedf399f73c782e0c531ebb3..b626fda45721479d76f79214fa5bb6ee7a0713b8 100644 (file)
@@ -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;
                                }
index 077362edacb72ea571cdc49bc80577e022778c24..00eb9b48e7e8ebbd911ac379dff68ce6d8ff504f 100644 (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" );
+} );