]> source.dussan.org Git - jquery.git/commitdiff
Fixes #13550. .data should not miss attr() set data-* with hyphenated property names...
authorMichał Gołębiowski <m.goleb@gmail.com>
Sat, 2 Mar 2013 18:04:48 +0000 (13:04 -0500)
committerRick Waldron <waldron.rick@gmail.com>
Sat, 2 Mar 2013 18:04:48 +0000 (13:04 -0500)
src/data.js
test/unit/data.js

index 66fe1134dd47b545c08c708469223a6f03b1a443..906d85f3a9e79c07667589d82f9977076dbe4826 100644 (file)
@@ -30,7 +30,7 @@ Data.prototype = {
                if ( !unlock ) {
                        unlock = Data.uid++;
                        descriptor[ this.expando ] = { value: unlock };
-                       
+
                        // Secure it in a non-enumerable, non-writable property
                        try {
                                Object.defineProperties( owner, descriptor );
@@ -312,7 +312,8 @@ jQuery.fn.extend({
 });
 
 function dataAttr( elem, key, data ) {
-       var name;
+       var name,
+                       camelKey = jQuery.camelCase( key );
 
        // If nothing was found internally, try to fetch any
        // data from the HTML5 data-* attribute
@@ -333,7 +334,7 @@ function dataAttr( elem, key, data ) {
                        } catch( e ) {}
 
                        // Make sure we set the data so it isn't changed later
-                       data_user.set( elem, key, data );
+                       data_user.set( elem, camelKey, data );
                } else {
                        data = undefined;
                }
index cd8183fe1934a9d628f1963235ad15ab39deb026..7ab58be3c873ce94c8f41d7f82728aae785c006c 100644 (file)
@@ -515,14 +515,22 @@ test(".data should not miss preset data-* w/ hyphenated property names", functio
 });
 
 test(".data should not miss attr() set data-* with hyphenated property names", function() {
-       expect(1);
+       expect(2);
+
+       var div1 = jQuery("<div/>").appendTo("#qunit-fixture");
+
+       div1.attr( "data-long-param", "test" );
+       div1.data( "long-param", { a: 2 });
+
+       deepEqual( div1.data("long-param"), { a: 2 }, "data with property long-param was found" );
 
-       var div = jQuery("<div/>").appendTo("#qunit-fixture");
+       var div2 = jQuery("<div/>").appendTo("#qunit-fixture");
 
-       div.attr( "data-long-param", "test" );
-       div.data( "long-param", { a: 2 });
+       div2.attr( "data-long-param", "test" );
+       div2.data( "long-param" );
+       div2.data( "long-param", { a: 2 });
 
-       deepEqual( div.data("long-param"), { a: 2 }, "data with property long-param was found" );
+       deepEqual( div2.data("long-param"), { a: 2 }, "data with property long-param was found" );
 });
 
 test("jQuery.data supports interoperable hyphenated/camelCase get/set of properties with arbitrary non-null|NaN|undefined values", function() {