Commit d8289964 authored by Rick Waldron's avatar Rick Waldron Committed by Dave Methvin

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

parent 6c8dd7e7
...@@ -814,11 +814,11 @@ function buildParams( prefix, obj, traditional, add ) { ...@@ -814,11 +814,11 @@ function buildParams( prefix, obj, traditional, add ) {
// a server error. Possible fixes are to modify rack's // a server error. Possible fixes are to modify rack's
// deserialization algorithm or to provide an option or flag // deserialization algorithm or to provide an option or flag
// to force array serialization to be shallow. // 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. // Serialize object item.
for ( var name in obj ) { for ( var name in obj ) {
buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add ); buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
......
...@@ -1032,16 +1032,24 @@ test("jQuery.param()", function() { ...@@ -1032,16 +1032,24 @@ test("jQuery.param()", function() {
}); });
test("jQuery.param() Constructed prop values", 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" ); 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" ); 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" ); 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() { test("synchronous request", function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment