]> source.dussan.org Git - jquery.git/commitdiff
Data: camelCasing should not ignore case
authorTimmy Willison <timmywillisn@gmail.com>
Mon, 4 May 2015 14:49:21 +0000 (10:49 -0400)
committerTimmy Willison <timmywillisn@gmail.com>
Mon, 4 May 2015 14:49:21 +0000 (10:49 -0400)
Fixes gh-2070

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

index 0c72801d67cd72dee8b2d089f154d2d7f23fab5a..b3e9a71037b840063f20ac6b1f9a9bdd87369425 100644 (file)
@@ -27,7 +27,7 @@ var
 
        // Matches dashed string for camelizing
        rmsPrefix = /^-ms-/,
-       rdashAlpha = /-([a-z])/gi,
+       rdashAlpha = /-([a-z])/g,
 
        // Used by jQuery.camelCase as callback to replace()
        fcamelCase = function( all, letter ) {
index aeca493b71b029e1ac4eb084fd4efdd63deacd73..c08550b1b9969fb3cd6276e2b29a7527cf0de41e 100644 (file)
@@ -615,6 +615,16 @@ test(".data always sets data with the camelCased key (gh-2257)", function() {
        });
 });
 
+test( ".data should not strip more than one hyphen when camelCasing (gh-2070)", function() {
+       expect( 3 );
+       var div = jQuery( "<div data-nested-single='single' data-nested--double='double' data-nested---triple='triple'></div>" ).appendTo( "#qunit-fixture" ),
+               allData = div.data();
+
+       equal( allData.nestedSingle, "single", "Key is correctly camelCased" );
+       equal( allData[ "nested-Double" ], "double", "Key with double hyphens is correctly camelCased" );
+       equal( allData[ "nested--Triple" ], "triple", "Key with triple hyphens is correctly camelCased" );
+});
+
 test(".data supports interoperable hyphenated/camelCase get/set of properties with arbitrary non-null|NaN|undefined values", function() {
 
        var div = jQuery("<div/>", { id: "hyphened" }).appendTo("#qunit-fixture"),