From cf16f860b05b7bffeb2382a0a55bb85c69b2abb5 Mon Sep 17 00:00:00 2001 From: Timmy Willison Date: Mon, 4 May 2015 10:49:21 -0400 Subject: [PATCH] Data: camelCasing should not ignore case Fixes gh-2070 --- src/core.js | 2 +- test/unit/data.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/core.js b/src/core.js index 2bbec5c51..858c04770 100644 --- a/src/core.js +++ b/src/core.js @@ -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 ) { diff --git a/test/unit/data.js b/test/unit/data.js index b691bd1ba..68eb589ea 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -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( "
" ).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("
", { id: "hyphened" }).appendTo("#qunit-fixture"), datas = {