Skip to content

Commit 0742056

Browse files
rwaldrontimmywil
authored andcommitted
Landing pull request 403. Check for both camelized and hyphenated data property names; Fixes #9301.
More Details: - jquery#403 - http://bugs.jquery.com/ticket/9301
1 parent c3c001c commit 0742056

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/data.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ jQuery.extend({
108108
return thisCache[ internalKey ] && thisCache[ internalKey ].events;
109109
}
110110

111-
return getByName ? thisCache[ jQuery.camelCase( name ) ] : thisCache;
111+
return getByName ?
112+
// Check for both converted-to-camel and non-converted data property names
113+
thisCache[ jQuery.camelCase( name ) ] || thisCache[ name ] :
114+
thisCache;
112115
},
113116

114117
removeData: function( elem, name, pvt /* Internal Use Only */ ) {

test/unit/data.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,3 +508,20 @@ test("jQuery.data should follow html5 specification regarding camel casing", fun
508508

509509
div.remove();
510510
});
511+
512+
test("jQuery.data should not miss data with preset hyphenated property names", function() {
513+
514+
expect(2);
515+
516+
var div = jQuery("<div/>", { id: "hyphened" }).appendTo("#qunit-fixture"),
517+
test = {
518+
"camelBar": "camelBar",
519+
"hyphen-foo": "hyphen-foo"
520+
};
521+
522+
div.data( test );
523+
524+
jQuery.each( test , function(i, k) {
525+
equal( div.data(k), k, "data with property '"+k+"' was correctly found");
526+
});
527+
});

0 commit comments

Comments
 (0)