Make sure the data- number has at least one number in it before passing to isNaN. Thanks to @cms in 8ebb9b22df for a heads-up.

This commit is contained in:
jeresig 2010-09-22 07:34:31 -04:00
parent e3463946e1
commit 9ad7c21e70
2 changed files with 6 additions and 2 deletions

View File

@ -157,7 +157,7 @@ jQuery.fn.extend({
data = data === "true" ? true : data = data === "true" ? true :
data === "false" ? false : data === "false" ? false :
data === "null" ? null : data === "null" ? null :
!isNaN( data ) ? parseFloat( data ) : /\d/.test( data ) && !isNaN( data ) ? parseFloat( data ) :
rbrace.test( data ) ? jQuery.parseJSON( data ) : rbrace.test( data ) ? jQuery.parseJSON( data ) :
data; data;
} catch( e ) {} } catch( e ) {}

View File

@ -158,7 +158,7 @@ test(".data(String) and .data(String, Object)", function() {
}); });
test("data-* attributes", function() { test("data-* attributes", function() {
expect(25); expect(27);
var div = jQuery("<div>"), var div = jQuery("<div>"),
child = jQuery("<div data-myobj='old data' data-ignored=\"DOM\"></div>"); child = jQuery("<div data-myobj='old data' data-ignored=\"DOM\"></div>");
@ -189,6 +189,8 @@ test("data-* attributes", function() {
.attr("data-pointbad2", "-.") .attr("data-pointbad2", "-.")
.attr("data-badjson", "{123}") .attr("data-badjson", "{123}")
.attr("data-badjson2", "[abc]") .attr("data-badjson2", "[abc]")
.attr("data-empty", "")
.attr("data-space", " ")
.attr("data-null", "null") .attr("data-null", "null")
.attr("data-string", "test"); .attr("data-string", "test");
@ -201,6 +203,8 @@ test("data-* attributes", function() {
strictEqual( child.data('pointbad2'), "-.", "Bad number read from attribute"); strictEqual( child.data('pointbad2'), "-.", "Bad number read from attribute");
strictEqual( child.data('badjson'), "{123}", "Bad number read from attribute"); strictEqual( child.data('badjson'), "{123}", "Bad number read from attribute");
strictEqual( child.data('badjson2'), "[abc]", "Bad number read from attribute"); strictEqual( child.data('badjson2'), "[abc]", "Bad number read from attribute");
strictEqual( child.data('empty'), "", "Empty string read from attribute");
strictEqual( child.data('space'), " ", "Empty string read from attribute");
strictEqual( child.data('null'), null, "Primitive null read from attribute"); strictEqual( child.data('null'), null, "Primitive null read from attribute");
strictEqual( child.data('string'), "test", "Typical string read from attribute"); strictEqual( child.data('string'), "test", "Typical string read from attribute");