aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjeresig <jeresig@gmail.com>2010-09-22 07:34:31 -0400
committerjeresig <jeresig@gmail.com>2010-09-22 07:34:31 -0400
commit9ad7c21e701f827e108de038ff704f1e9b7022da (patch)
tree15d2ca9cb26016692f18b7c0034384d305dda6b2
parente3463946e19f2eb53d909fc2b59cc1c8636d21bd (diff)
downloadjquery-9ad7c21e701f827e108de038ff704f1e9b7022da.tar.gz
jquery-9ad7c21e701f827e108de038ff704f1e9b7022da.zip
Make sure the data- number has at least one number in it before passing to isNaN. Thanks to @cms in 8ebb9b22df32fe5739a48087b6e33abb9f5cda49 for a heads-up.
-rw-r--r--src/data.js2
-rw-r--r--test/unit/data.js6
2 files changed, 6 insertions, 2 deletions
diff --git a/src/data.js b/src/data.js
index cf3cf606a..3bd4b9715 100644
--- a/src/data.js
+++ b/src/data.js
@@ -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 ) {}
diff --git a/test/unit/data.js b/test/unit/data.js
index 058f23f40..03d38c9cf 100644
--- a/test/unit/data.js
+++ b/test/unit/data.js
@@ -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");