Skip to content

Commit 166b9d2

Browse files
rwaldrondmethvin
authored andcommitted
Fix #10466. jQuery.param() should treat object-wrapped primitives as primitives.
1 parent 6c2a501 commit 166b9d2

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/ajax.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ function buildParams( prefix, obj, traditional, add ) {
818818
}
819819
});
820820

821-
} else if ( !traditional && obj != null && typeof obj === "object" ) {
821+
} else if ( !traditional && jQuery.isPlainObject( obj ) ) {
822822
// Serialize object item.
823823
for ( var name in obj ) {
824824
buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );

test/unit/ajax.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,19 @@ test("jQuery.param()", function() {
10311031
equal( jQuery.param( params, false ), "test%5Blength%5D=3&test%5Bfoo%5D=bar", "Sub-object with a length property" );
10321032
});
10331033

1034+
test("jQuery.param() Constructed prop values", function() {
1035+
expect(3);
1036+
1037+
var params = {"test": new String("foo") };
1038+
equal( jQuery.param( params, false ), "test=foo", "Do not mistake new String() for a plain object" );
1039+
1040+
params = {"test": new Number(5) };
1041+
equal( jQuery.param( params, false ), "test=5", "Do not mistake new Number() for a plain object" );
1042+
1043+
params = {"test": new Date() };
1044+
ok( jQuery.param( params, false ), "(Non empty string returned) Do not mistake new Date() for a plain object" );
1045+
});
1046+
10341047
test("synchronous request", function() {
10351048
expect(1);
10361049
ok( /^{ "data"/.test( jQuery.ajax({url: url("data/json_obj.js"), dataType: "text", async: false}).responseText ), "check returned text" );

0 commit comments

Comments
 (0)