Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Check for both camelized and hyphenated data property names; Fixes #9301 #403

Closed
wants to merge 1 commit into from

2 participants

Rick Waldron Timmy Willison
Rick Waldron
Collaborator

No description provided.

Timmy Willison
Collaborator

Landed in commit 0742056.

Timmy Willison timmywil closed this
Mescoda mescoda referenced this pull request from a commit in mescoda/jquery
Rick Waldron rwaldron Landing pull request 403. Check for both camelized and hyphenated dat…
…a property names; Fixes #9301.

More Details:
 - jquery#403
 - http://bugs.jquery.com/ticket/9301
b05b10f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 1 deletion.
  1. +4 −1 src/data.js
  2. +17 −0 test/unit/data.js
5 src/data.js
View
@@ -108,7 +108,10 @@ jQuery.extend({
return thisCache[ internalKey ] && thisCache[ internalKey ].events;
}
- return getByName ? thisCache[ jQuery.camelCase( name ) ] : thisCache;
+ return getByName ?
+ // Check for both converted-to-camel and non-converted data property names
+ thisCache[ jQuery.camelCase( name ) ] || thisCache[ name ] :
+ thisCache;
},
removeData: function( elem, name, pvt /* Internal Use Only */ ) {
17 test/unit/data.js
View
@@ -508,3 +508,20 @@ test("jQuery.data should follow html5 specification regarding camel casing", fun
div.remove();
});
+
+test("jQuery.data should not miss data with preset hyphenated property names", function() {
+
+ expect(2);
+
+ var div = jQuery("<div/>", { id: "hyphened" }).appendTo("#qunit-fixture"),
+ test = {
+ "camelBar": "camelBar",
+ "hyphen-foo": "hyphen-foo"
+ };
+
+ div.data( test );
+
+ jQuery.each( test , function(i, k) {
+ equal( div.data(k), k, "data with property '"+k+"' was correctly found");
+ });
+});
Something went wrong with that request. Please try again.