From 147726af127bce98b4e9dfe517d68f4a1ea0c1fc Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Fri, 21 Jun 2013 15:45:30 -0400 Subject: [PATCH] Fixes #14047 jQuery.data should not miss data-* w/ hyphenated property names http://bugs.jquery.com/ticket/14047 Signed-off-by: Rick Waldron --- src/data.js | 7 ++++++- test/unit/data.js | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/data.js b/src/data.js index 86dd4273f..96afe6f4e 100644 --- a/src/data.js +++ b/src/data.js @@ -113,6 +113,7 @@ Data.prototype = { cache : cache[ key ]; }, access: function( owner, key, value ) { + var stored; // In cases where either: // // 1. No key was specified @@ -126,7 +127,11 @@ Data.prototype = { // if ( key === undefined || ((key && typeof key === "string") && value === undefined) ) { - return this.get( owner, key ); + + stored = this.get( owner, key ); + + return stored !== undefined ? + stored : this.get( owner, jQuery.camelCase(key) ); } // [*]When the key is not a string, or both a key and value diff --git a/test/unit/data.js b/test/unit/data.js index 1e36ea5c5..ad43d34cd 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -529,6 +529,17 @@ test(".data should not miss preset data-* w/ hyphenated property names", functio }); }); +test("jQuery.data should not miss data-* w/ hyphenated property names #14047", function() { + + expect(1); + + var div = jQuery("
"); + + div.data( "foo-bar", "baz" ); + + equal( jQuery.data(div[0], "foo-bar"), "baz", "data with property 'foo-bar' was correctly found"); +}); + test(".data should not miss attr() set data-* with hyphenated property names", function() { expect(2); -- 2.39.5