Skip to content
Permalink
Browse files
Tweaked the data number RegExp some to handle some other edge cases.
  • Loading branch information
jeresig committed Sep 21, 2010
1 parent 4a46f3d commit d5d4e4d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
@@ -1,7 +1,7 @@
(function( jQuery ) {

var windowData = {},
rnum = /^-?[0-9.]+$/;
rnum = /^-?\d+(?:\.\d+)$/;

jQuery.extend({
cache: {},
@@ -158,7 +158,7 @@ test(".data(String) and .data(String, Object)", function() {
});

test("data-* attributes", function() {
expect(20);
expect(22);
var div = jQuery("<div>"),
child = jQuery("<div data-myobj='old data' data-ignored=\"DOM\"></div>");

@@ -184,13 +184,17 @@ test("data-* attributes", function() {
.attr("data-false", "false")
.attr("data-five", "5")
.attr("data-point", "5.5")
.attr("data-pointbad", "5..5")
.attr("data-pointbad2", "-.")
.attr("data-null", "null")
.attr("data-string", "test");

equals( child.data('true'), true, "Primitive true read from attribute");
equals( child.data('false'), false, "Primitive false read from attribute");
equals( child.data('five'), 5, "Primitive number read from attribute");
equals( child.data('point'), 5.5, "Primitive number read from attribute");
equals( child.data('pointbad'), "5..5", "Bad number read from attribute");
equals( child.data('pointbad2'), "-.", "Bad number read from attribute");
equals( child.data('null'), null, "Primitive null read from attribute");
equals( child.data('string'), "test", "Typical string read from attribute");

0 comments on commit d5d4e4d

Please sign in to comment.