Skip to content

Commit 2862a07

Browse files
committed
Data: do not include digits when camelCasing
Fixes gh-1751
1 parent a873558 commit 2862a07

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/core.js

+1-1
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 = /-([\da-z])/gi,
30+
rdashAlpha = /-([a-z])/gi,
3131

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

test/unit/core.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,7 @@ test("jQuery.camelCase()", function() {
15031503
"foo-bar": "fooBar",
15041504
"foo-bar-baz": "fooBarBaz",
15051505
"girl-u-want": "girlUWant",
1506-
"the-4th-dimension": "the4thDimension",
1506+
"the-4th-dimension": "the-4thDimension",
15071507
"-o-tannenbaum": "OTannenbaum",
15081508
"-moz-illa": "MozIlla",
15091509
"-ms-take": "msTake"

test/unit/data.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,14 @@ test(".data(object) does not retain references. #13815", function() {
259259
});
260260

261261
test("data-* attributes", function() {
262-
expect( 43 );
262+
expect( 46 );
263263

264264
var prop, i, l, metadata, elem,
265265
obj, obj2, check, num, num2,
266266
parseJSON = jQuery.parseJSON,
267267
div = jQuery("<div>"),
268-
child = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>"),
269-
dummy = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>");
268+
child = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test' data-foo-42='boosh'></div>"),
269+
dummy = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test' data-foo-42='boosh'></div>");
270270

271271
equal( div.data("attr"), undefined, "Check for non-existing data-attr attribute" );
272272

@@ -283,6 +283,7 @@ test("data-* attributes", function() {
283283

284284
child.appendTo("#qunit-fixture");
285285
equal( child.data("myobj"), "old data", "Value accessed from data-* attribute");
286+
equal( child.data("foo-42"), "boosh", "camelCasing does not affect numbers (#1751)" );
286287

287288
child.data("myobj", "replaced");
288289
equal( child.data("myobj"), "replaced", "Original data overwritten");
@@ -292,7 +293,7 @@ test("data-* attributes", function() {
292293

293294
obj = child.data();
294295
obj2 = dummy.data();
295-
check = [ "myobj", "ignored", "other" ];
296+
check = [ "myobj", "ignored", "other", "foo-42" ];
296297
num = 0;
297298
num2 = 0;
298299

0 commit comments

Comments
 (0)