Skip to content

Commit 96bb57d

Browse files
sindresorhusdmethvin
authored andcommitted
Fix #11309. Recognize hexadecimal in data attributes.
1 parent 974e4af commit 96bb57d

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ function dataAttr( elem, key, data ) {
333333
data = data === "true" ? true :
334334
data === "false" ? false :
335335
data === "null" ? null :
336-
jQuery.isNumeric( data ) ? parseFloat( data ) :
336+
jQuery.isNumeric( data ) ? +data :
337337
rbrace.test( data ) ? jQuery.parseJSON( data ) :
338338
data;
339339
} catch( e ) {}

test/unit/data.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ test(".data(String) and .data(String, Object)", function() {
298298
});
299299

300300
test("data-* attributes", function() {
301-
expect(37);
301+
expect(38);
302302
var div = jQuery("<div>"),
303303
child = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>"),
304304
dummy = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>");
@@ -356,6 +356,7 @@ test("data-* attributes", function() {
356356
.attr("data-five", "5")
357357
.attr("data-point", "5.5")
358358
.attr("data-pointe", "5.5E3")
359+
.attr("data-hexadecimal", "0x42")
359360
.attr("data-pointbad", "5..5")
360361
.attr("data-pointbad2", "-.")
361362
.attr("data-badjson", "{123}")
@@ -370,6 +371,7 @@ test("data-* attributes", function() {
370371
strictEqual( child.data("five"), 5, "Primitive number read from attribute");
371372
strictEqual( child.data("point"), 5.5, "Primitive number read from attribute");
372373
strictEqual( child.data("pointe"), 5500, "Primitive number read from attribute");
374+
strictEqual( child.data("hexadecimal"), 66, "Hexadecimal number read from attribute");
373375
strictEqual( child.data("pointbad"), "5..5", "Bad number read from attribute");
374376
strictEqual( child.data("pointbad2"), "-.", "Bad number read from attribute");
375377
strictEqual( child.data("badjson"), "{123}", "Bad number read from attribute");

0 commit comments

Comments
 (0)