Skip to content

Commit

Permalink
Fix #10466. jQuery.param() should treat object-wrapped primitives as …
Browse files Browse the repository at this point in the history
…primitives.
  • Loading branch information
rwaldron authored and dmethvin committed Dec 6, 2011
1 parent 6c2a501 commit 166b9d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
13 changes: 13 additions & 0 deletions test/unit/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down

0 comments on commit 166b9d2

Please sign in to comment.