diff options
author | Rick Waldron <waldron.rick@gmail.com> | 2012-01-12 20:14:51 -0500 |
---|---|---|
committer | Dave Methvin <dave.methvin@gmail.com> | 2012-01-12 20:14:51 -0500 |
commit | d8289964788b6d5a31c2f89746c78079fb8a9869 (patch) | |
tree | f280d858977a7ff695dff05413b61089645dcd3c | |
parent | 6c8dd7e7d3a00133591d4f9c05c207900234e11e (diff) | |
download | jquery-d8289964788b6d5a31c2f89746c78079fb8a9869.tar.gz jquery-d8289964788b6d5a31c2f89746c78079fb8a9869.zip |
Fix #10978: Let jQuery.param() accept non-native constructed objects.
-rw-r--r-- | src/ajax.js | 4 | ||||
-rw-r--r-- | test/unit/ajax.js | 16 |
2 files changed, 14 insertions, 6 deletions
diff --git a/src/ajax.js b/src/ajax.js index 76e9ef443..a07ff6ef3 100644 --- a/src/ajax.js +++ b/src/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 ); diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 8e50153ee..ca851910a 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -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() { |