From 07420566452622f37b01e69bbbdcbeeb5317e065 Mon Sep 17 00:00:00 2001 From: rwldrn Date: Mon, 6 Jun 2011 20:18:36 -0400 Subject: [PATCH] Landing pull request 403. Check for both camelized and hyphenated data property names; Fixes #9301. More Details: - https://github.com/jquery/jquery/pull/403 - http://bugs.jquery.com/ticket/9301 --- src/data.js | 5 ++++- test/unit/data.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/data.js b/src/data.js index c019a64e2..f69d9decd 100644 --- a/src/data.js +++ b/src/data.js @@ -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 */ ) { diff --git a/test/unit/data.js b/test/unit/data.js index 1af2077ec..87a3de339 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -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("
", { 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"); + }); +}); -- 2.39.5