Skip to content
Permalink
Browse files

Fix #10978: Let jQuery.param() accept non-native constructed objects.

  • Loading branch information...
rwaldron authored and dmethvin committed Jan 13, 2012
1 parent 6c8dd7e commit d8289964788b6d5a31c2f89746c78079fb8a9869
Showing with 14 additions and 6 deletions.
  1. +2 −2 src/ajax.js
  2. +12 −4 test/unit/ajax.js
@@ -814,11 +814,11 @@ function buildParams( prefix, obj, traditional, add ) {
// a server error. Possible fixes are to modify rack's
// deserialization algorithm or to provide an option or flag
// to force array serialization to be shallow.
buildParams( prefix + "[" + ( typeof v === "object" || jQuery.isArray(v) ? i : "" ) + "]", v, traditional, add );
buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
}
});

} else if ( !traditional && jQuery.isPlainObject( obj ) ) {
} else if ( !traditional && jQuery.type( obj ) === "object" ) {
// Serialize object item.
for ( var name in obj ) {
buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
@@ -1032,16 +1032,24 @@ test("jQuery.param()", function() {
});

test("jQuery.param() Constructed prop values", function() {
expect(3);
expect( 4 );

var params = {"test": new String("foo") };
function Record() {
this.prop = "val";
}

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) };
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() };
params = { "test": new Date() };
ok( jQuery.param( params, false ), "(Non empty string returned) Do not mistake new Date() for a plain object" );

// should allow non-native constructed objects
params = { "test": new Record() };
equal( jQuery.param( params, false ), jQuery.param({ "test": { prop: "val" } }), "Allow non-native constructed objects" );
});

test("synchronous request", function() {

0 comments on commit d828996

Please sign in to comment.
You can’t perform that action at this time.