Skip to content
Permalink
Browse files
Make sure that data properties with hyphens are always accessed/set u…
…sing camelCase. Fixes #9124.
  • Loading branch information
jeresig committed May 10, 2011
1 parent 419b5e5 commit a5e407c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
@@ -98,7 +98,7 @@ jQuery.extend({
}

if ( data !== undefined ) {
thisCache[ name ] = data;
thisCache[ jQuery.camelCase( name ) ] = data;
}

// TODO: This is a hack for 1.5 ONLY. It will be removed in 1.6. Users should
@@ -108,7 +108,7 @@ jQuery.extend({
return thisCache[ internalKey ] && thisCache[ internalKey ].events;
}

return getByName ? thisCache[ name ] : thisCache;
return getByName ? thisCache[ jQuery.camelCase( name ) ] : thisCache;
},

removeData: function( elem, name, pvt /* Internal Use Only */ ) {
@@ -488,7 +488,7 @@ if (window.JSON && window.JSON.stringify) {
}

test("jQuery.data should follow html5 specification regarding camel casing", function() {
expect(6);
expect(8);

var div = jQuery("<div id='myObject' data-foo='a' data-foo-bar='b' data-foo-bar-baz='c'></div>")
.prependTo("body");
@@ -501,5 +501,10 @@ test("jQuery.data should follow html5 specification regarding camel casing", fun
equals(div.data("fooBar"), "b", "Verify multiple word data-* key");
equals(div.data("fooBarBaz"), "c", "Verify multiple word data-* key");

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

equals(div.data("fooBar"), "d", "Verify updated data-* key");
equals(div.data("foo-bar"), "d", "Verify updated data-* key");

div.remove();
});
});

0 comments on commit a5e407c

Please sign in to comment.