aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjeresig <jeresig@gmail.com>2010-09-21 08:20:31 -0400
committerjeresig <jeresig@gmail.com>2010-09-21 08:20:31 -0400
commit1f8a5e4bbc49c244051101765c46bd8f35e2aa32 (patch)
treea57aa334d81a310738011cd220d92d8a58e99015
parente7c2d3b45bf0e8fbe9d7c9316b6c5adb2c019ea3 (diff)
downloadjquery-1f8a5e4bbc49c244051101765c46bd8f35e2aa32.tar.gz
jquery-1f8a5e4bbc49c244051101765c46bd8f35e2aa32.zip
Make sure that the data- import also supports arrays.
-rw-r--r--src/data.js2
-rw-r--r--test/unit/data.js6
2 files changed, 5 insertions, 3 deletions
diff --git a/src/data.js b/src/data.js
index 44ad0c49e..abe46891d 100644
--- a/src/data.js
+++ b/src/data.js
@@ -2,7 +2,7 @@
var windowData = {},
rnum = /^-?\d+(?:\.\d+)$/,
- rbrace = /^{.*}$/;
+ rbrace = /^(?:{.*}|\[.*\])$/;
jQuery.extend({
cache: {},
diff --git a/test/unit/data.js b/test/unit/data.js
index f360daf7f..f87d7ae4f 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(23);
+ expect(24);
var div = jQuery("<div>"),
child = jQuery("<div data-myobj='old data' data-ignored=\"DOM\"></div>");
@@ -187,6 +187,7 @@ test("data-* attributes", function() {
.attr("data-pointbad", "5..5")
.attr("data-pointbad2", "-.")
.attr("data-badjson", "{123}")
+ .attr("data-badjson2", "[abc]")
.attr("data-null", "null")
.attr("data-string", "test");
@@ -197,6 +198,7 @@ test("data-* attributes", function() {
equals( child.data('pointbad'), "5..5", "Bad number read from attribute");
equals( child.data('pointbad2'), "-.", "Bad number read from attribute");
equals( child.data('badjson'), "{123}", "Bad number read from attribute");
+ equals( child.data('badjson2'), "[abc]", "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");
@@ -219,7 +221,7 @@ test("data-* attributes", function() {
break;
case 3:
equals(jQuery(elem).data("number"), true, "Check number property");
- equals(jQuery(elem).data("stuff"), "[2,8]", "Check stuff property");
+ same(jQuery(elem).data("stuff"), [2,8], "Check stuff property");
break;
default:
ok(false, ["Assertion failed on index ", index, ", with data ", data].join(''));