Skip to content

Commit cf16f86

Browse files
committed
Data: camelCasing should not ignore case
Fixes gh-2070
1 parent 0204c30 commit cf16f86

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
@@ -26,7 +26,7 @@ var
2626

2727
// Matches dashed string for camelizing
2828
rmsPrefix = /^-ms-/,
29-
rdashAlpha = /-([a-z])/gi,
29+
rdashAlpha = /-([a-z])/g,
3030

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

test/unit/data.js

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

595+
test( ".data should not strip more than one hyphen when camelCasing (gh-2070)", function() {
596+
expect( 3 );
597+
var div = jQuery( "<div data-nested-single='single' data-nested--double='double' data-nested---triple='triple'></div>" ).appendTo( "#qunit-fixture" ),
598+
allData = div.data();
599+
600+
equal( allData.nestedSingle, "single", "Key is correctly camelCased" );
601+
equal( allData[ "nested-Double" ], "double", "Key with double hyphens is correctly camelCased" );
602+
equal( allData[ "nested--Triple" ], "triple", "Key with triple hyphens is correctly camelCased" );
603+
});
604+
595605
test(".data supports interoperable hyphenated/camelCase get/set of properties with arbitrary non-null|NaN|undefined values", function() {
596606
var div = jQuery("<div/>", { id: "hyphened" }).appendTo("#qunit-fixture"),
597607
datas = {

0 commit comments

Comments
 (0)