From: Sindre Sorhus Date: Fri, 10 Feb 2012 01:25:43 +0000 (-0500) Subject: Fix #11309. Recognize hexadecimal in data attributes. X-Git-Tag: 1.7.2rc1~34 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=96bb57d4ef49a0ab8f753108cc016fa215e237f4;p=jquery.git Fix #11309. Recognize hexadecimal in data attributes. --- diff --git a/src/data.js b/src/data.js index 26bef32af..017bd2efd 100644 --- a/src/data.js +++ b/src/data.js @@ -333,7 +333,7 @@ function dataAttr( elem, key, data ) { data = data === "true" ? true : data === "false" ? false : data === "null" ? null : - jQuery.isNumeric( data ) ? parseFloat( data ) : + jQuery.isNumeric( data ) ? +data : rbrace.test( data ) ? jQuery.parseJSON( data ) : data; } catch( e ) {} diff --git a/test/unit/data.js b/test/unit/data.js index 006e29e6a..7598ba8be 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -298,7 +298,7 @@ test(".data(String) and .data(String, Object)", function() { }); test("data-* attributes", function() { - expect(37); + expect(38); var div = jQuery("
"), child = jQuery("
"), dummy = jQuery("
"); @@ -356,6 +356,7 @@ test("data-* attributes", function() { .attr("data-five", "5") .attr("data-point", "5.5") .attr("data-pointe", "5.5E3") + .attr("data-hexadecimal", "0x42") .attr("data-pointbad", "5..5") .attr("data-pointbad2", "-.") .attr("data-badjson", "{123}") @@ -370,6 +371,7 @@ test("data-* attributes", function() { strictEqual( child.data("five"), 5, "Primitive number read from attribute"); strictEqual( child.data("point"), 5.5, "Primitive number read from attribute"); strictEqual( child.data("pointe"), 5500, "Primitive number read from attribute"); + strictEqual( child.data("hexadecimal"), 66, "Hexadecimal number read from attribute"); strictEqual( child.data("pointbad"), "5..5", "Bad number read from attribute"); strictEqual( child.data("pointbad2"), "-.", "Bad number read from attribute"); strictEqual( child.data("badjson"), "{123}", "Bad number read from attribute");