Skip to content

Commit 8e8fa6d

Browse files
rwaldrondmethvin
authored andcommitted
Bug in rmultidash. Fixes #10194
1 parent 4bc691a commit 8e8fa6d

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/data.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(function( jQuery ) {
22

33
var rbrace = /^(?:\{.*\}|\[.*\])$/,
4-
rmultiDash = /([a-z])([A-Z])/g;
4+
rmultiDash = /([A-Z])/g;
55

66
jQuery.extend({
77
cache: {},
@@ -316,7 +316,8 @@ function dataAttr( elem, key, data ) {
316316
// If nothing was found internally, try to fetch any
317317
// data from the HTML5 data-* attribute
318318
if ( data === undefined && elem.nodeType === 1 ) {
319-
var name = "data-" + key.replace( rmultiDash, "$1-$2" ).toLowerCase();
319+
320+
var name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
320321

321322
data = elem.getAttribute( name );
322323

test/unit/data.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -488,23 +488,26 @@ if (window.JSON && window.JSON.stringify) {
488488
}
489489

490490
test("jQuery.data should follow html5 specification regarding camel casing", function() {
491-
expect(8);
491+
expect(10);
492492

493-
var div = jQuery("<div id='myObject' data-foo='a' data-foo-bar='b' data-foo-bar-baz='c'></div>")
493+
var div = jQuery("<div id='myObject' data-w-t-f='ftw' data-big-a-little-a='bouncing-b' data-foo='a' data-foo-bar='b' data-foo-bar-baz='c'></div>")
494494
.prependTo("body");
495495

496-
equals(div.data().foo, "a", "Verify single word data-* key");
497-
equals(div.data().fooBar, "b", "Verify multiple word data-* key");
498-
equals(div.data().fooBarBaz, "c", "Verify multiple word data-* key");
496+
equal( div.data().wTF, "ftw", "Verify single letter data-* key" );
497+
equal( div.data().bigALittleA, "bouncing-b", "Verify single letter mixed data-* key" );
499498

500-
equals(div.data("foo"), "a", "Verify single word data-* key");
501-
equals(div.data("fooBar"), "b", "Verify multiple word data-* key");
502-
equals(div.data("fooBarBaz"), "c", "Verify multiple word data-* key");
499+
equal( div.data().foo, "a", "Verify single word data-* key" );
500+
equal( div.data().fooBar, "b", "Verify multiple word data-* key" );
501+
equal( div.data().fooBarBaz, "c", "Verify multiple word data-* key" );
502+
503+
equal( div.data("foo"), "a", "Verify single word data-* key" );
504+
equal( div.data("fooBar"), "b", "Verify multiple word data-* key" );
505+
equal( div.data("fooBarBaz"), "c", "Verify multiple word data-* key" );
503506

504507
div.data("foo-bar", "d");
505508

506-
equals(div.data("fooBar"), "d", "Verify updated data-* key");
507-
equals(div.data("foo-bar"), "d", "Verify updated data-* key");
509+
equal( div.data("fooBar"), "d", "Verify updated data-* key" );
510+
equal( div.data("foo-bar"), "d", "Verify updated data-* key" );
508511

509512
div.remove();
510513
});

0 commit comments

Comments
 (0)