Fixes #13550. .data should not miss attr() set data-* with hyphenated property names. Closes gh-1189

This commit is contained in:
Michał Gołębiowski 2013-03-02 13:04:48 -05:00 committed by Rick Waldron
parent 8f7218198d
commit 761b96c301
2 changed files with 17 additions and 8 deletions

View File

@ -312,7 +312,8 @@ jQuery.fn.extend({
}); });
function dataAttr( elem, key, data ) { function dataAttr( elem, key, data ) {
var name; var name,
camelKey = jQuery.camelCase( key );
// If nothing was found internally, try to fetch any // If nothing was found internally, try to fetch any
// data from the HTML5 data-* attribute // data from the HTML5 data-* attribute
@ -333,7 +334,7 @@ function dataAttr( elem, key, data ) {
} catch( e ) {} } catch( e ) {}
// Make sure we set the data so it isn't changed later // Make sure we set the data so it isn't changed later
data_user.set( elem, key, data ); data_user.set( elem, camelKey, data );
} else { } else {
data = undefined; data = undefined;
} }

View File

@ -515,14 +515,22 @@ test(".data should not miss preset data-* w/ hyphenated property names", functio
}); });
test(".data should not miss attr() set data-* with hyphenated property names", function() { test(".data should not miss attr() set data-* with hyphenated property names", function() {
expect(1); expect(2);
var div = jQuery("<div/>").appendTo("#qunit-fixture"); var div1 = jQuery("<div/>").appendTo("#qunit-fixture");
div.attr( "data-long-param", "test" ); div1.attr( "data-long-param", "test" );
div.data( "long-param", { a: 2 }); div1.data( "long-param", { a: 2 });
deepEqual( div.data("long-param"), { a: 2 }, "data with property long-param was found" ); deepEqual( div1.data("long-param"), { a: 2 }, "data with property long-param was found" );
var div2 = jQuery("<div/>").appendTo("#qunit-fixture");
div2.attr( "data-long-param", "test" );
div2.data( "long-param" );
div2.data( "long-param", { a: 2 });
deepEqual( div2.data("long-param"), { a: 2 }, "data with property long-param was found" );
}); });
test("jQuery.data supports interoperable hyphenated/camelCase get/set of properties with arbitrary non-null|NaN|undefined values", function() { test("jQuery.data supports interoperable hyphenated/camelCase get/set of properties with arbitrary non-null|NaN|undefined values", function() {