Skip to content

Commit 172cad8

Browse files
committed
Data: camelCasing should not ignore case
Fixes gh-2070
1 parent 0e79098 commit 172cad8

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var
2727

2828
// Matches dashed string for camelizing
2929
rmsPrefix = /^-ms-/,
30-
rdashAlpha = /-([a-z])/gi,
30+
rdashAlpha = /-([a-z])/g,
3131

3232
// Used by jQuery.camelCase as callback to replace()
3333
fcamelCase = function( all, letter ) {

test/unit/data.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,16 @@ test(".data always sets data with the camelCased key (gh-2257)", function() {
615615
});
616616
});
617617

618+
test( ".data should not strip more than one hyphen when camelCasing (gh-2070)", function() {
619+
expect( 3 );
620+
var div = jQuery( "<div data-nested-single='single' data-nested--double='double' data-nested---triple='triple'></div>" ).appendTo( "#qunit-fixture" ),
621+
allData = div.data();
622+
623+
equal( allData.nestedSingle, "single", "Key is correctly camelCased" );
624+
equal( allData[ "nested-Double" ], "double", "Key with double hyphens is correctly camelCased" );
625+
equal( allData[ "nested--Triple" ], "triple", "Key with triple hyphens is correctly camelCased" );
626+
});
627+
618628
test(".data supports interoperable hyphenated/camelCase get/set of properties with arbitrary non-null|NaN|undefined values", function() {
619629

620630
var div = jQuery("<div/>", { id: "hyphened" }).appendTo("#qunit-fixture"),

0 commit comments

Comments
 (0)