aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRick Waldron <waldron.rick@gmail.com>2011-12-06 16:02:54 -0500
committerDave Methvin <dave.methvin@gmail.com>2011-12-06 16:02:54 -0500
commit166b9d252a025009413eee1584dc364996dcb1c2 (patch)
treefa90edee9f733919470576995aa3f6e53435bf29
parent6c2a501de40a5f6b3ad382e2d309e5a10fce04d0 (diff)
downloadjquery-166b9d252a025009413eee1584dc364996dcb1c2.tar.gz
jquery-166b9d252a025009413eee1584dc364996dcb1c2.zip
Fix #10466. jQuery.param() should treat object-wrapped primitives as primitives.
-rw-r--r--src/ajax.js2
-rw-r--r--test/unit/ajax.js13
2 files changed, 14 insertions, 1 deletions
diff --git a/src/ajax.js b/src/ajax.js
index bb64b6863..3a384db64 100644
--- a/src/ajax.js
+++ b/src/ajax.js
@@ -818,7 +818,7 @@ function buildParams( prefix, obj, traditional, add ) {
}
});
- } else if ( !traditional && obj != null && typeof obj === "object" ) {
+ } else if ( !traditional && jQuery.isPlainObject( obj ) ) {
// Serialize object item.
for ( var name in obj ) {
buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
diff --git a/test/unit/ajax.js b/test/unit/ajax.js
index 9527beea1..8e50153ee 100644
--- a/test/unit/ajax.js
+++ b/test/unit/ajax.js
@@ -1031,6 +1031,19 @@ test("jQuery.param()", function() {
equal( jQuery.param( params, false ), "test%5Blength%5D=3&test%5Bfoo%5D=bar", "Sub-object with a length property" );
});
+test("jQuery.param() Constructed prop values", function() {
+ expect(3);
+
+ var params = {"test": new String("foo") };
+ equal( jQuery.param( params, false ), "test=foo", "Do not mistake new String() for a plain object" );
+
+ params = {"test": new Number(5) };
+ equal( jQuery.param( params, false ), "test=5", "Do not mistake new Number() for a plain object" );
+
+ params = {"test": new Date() };
+ ok( jQuery.param( params, false ), "(Non empty string returned) Do not mistake new Date() for a plain object" );
+});
+
test("synchronous request", function() {
expect(1);
ok( /^{ "data"/.test( jQuery.ajax({url: url("data/json_obj.js"), dataType: "text", async: false}).responseText ), "check returned text" );