]> 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:52 +0000 (10:49 -0400)
Fixes gh-2070

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

index 2bbec5c51e7662acb3690153c4b0dfae1dab7ecd..858c047707bee68b1e0d7c5caa80ce23647b7ece 100644 (file)
@@ -26,7 +26,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 b691bd1ba5d5db14548dae15d7862c13b0bc7eb7..68eb589ea17783d7a96da578845b883f16c4e67c 100644 (file)
@@ -592,6 +592,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"),
                datas = {