]> source.dussan.org Git - jquery.git/commitdiff
Make sure the data- number has at least one number in it before passing to isNaN...
authorjeresig <jeresig@gmail.com>
Wed, 22 Sep 2010 11:34:31 +0000 (07:34 -0400)
committerjeresig <jeresig@gmail.com>
Wed, 22 Sep 2010 11:34:31 +0000 (07:34 -0400)
src/data.js
test/unit/data.js

index cf3cf606a96d88fcc97820d68e92b6471352c7d6..3bd4b97158a0e42fb7906f723ea6f52ade00d85d 100644 (file)
@@ -157,7 +157,7 @@ jQuery.fn.extend({
                                                        data = data === "true" ? true :
                                                                data === "false" ? false :
                                                                data === "null" ? null :
-                                                               !isNaN( data ) ? parseFloat( data ) :
+                                                               /\d/.test( data ) && !isNaN( data ) ? parseFloat( data ) :
                                                                rbrace.test( data ) ? jQuery.parseJSON( data ) :
                                                                data;
                                                } catch( e ) {}
index 058f23f4041729c502bfadc8fca637118b6f258f..03d38c9cf9dd2ace1790f0daea17689d5c8a64f6 100644 (file)
@@ -158,7 +158,7 @@ test(".data(String) and .data(String, Object)", function() {
 });
 
 test("data-* attributes", function() {
-       expect(25);
+       expect(27);
        var div = jQuery("<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-badjson", "{123}")
                .attr("data-badjson2", "[abc]")
+               .attr("data-empty", "")
+               .attr("data-space", " ")
                .attr("data-null", "null")
                .attr("data-string", "test");
        
@@ -201,6 +203,8 @@ test("data-* attributes", function() {
        strictEqual( child.data('pointbad2'), "-.", "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('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('string'), "test", "Typical string read from attribute");