]> source.dussan.org Git - jquery.git/commitdiff
Serialize: Handle arrays with null values
authorDaniel Nill <daniellnill@gmail.com>
Fri, 7 Aug 2015 02:49:14 +0000 (19:49 -0700)
committerMichał Gołębiowski <m.goleb@gmail.com>
Mon, 7 Sep 2015 21:00:47 +0000 (23:00 +0200)
(cherry-picked from 3d7ce0a65f0707ff01a851822e57ba80adcff075)

Closes gh-2436

src/serialize.js
test/unit/serialize.js

index af0f572eb0731f31fbcebcc559cb945059bb1bb6..580bd7d00a0f72c23ae1b7702261ada07987530b 100644 (file)
@@ -28,7 +28,7 @@ function buildParams( prefix, obj, traditional, add ) {
 
                                // Item is non-scalar (array or object), encode its numeric index.
                                buildParams(
-                                       prefix + "[" + ( typeof v === "object" ? i : "" ) + "]",
+                                       prefix + "[" + ( jQuery.type( v ) === "object" ? i : "" ) + "]",
                                        v,
                                        traditional,
                                        add
index 047861530438de107f6e2f815968548ac9f52e93..a64593603ba49a91083366b5eb4421786b4ee965 100644 (file)
@@ -1,7 +1,7 @@
 QUnit.module( "serialize", { teardown: moduleTeardown } );
 
 QUnit.test( "jQuery.param()", function( assert ) {
-       assert.expect( 22 );
+       assert.expect( 23 );
 
        var params, settings;
 
@@ -77,6 +77,9 @@ QUnit.test( "jQuery.param()", function( assert ) {
        params = { "test": { "length": 3, "foo": "bar" } };
        assert.equal( jQuery.param( params, false ), "test%5Blength%5D=3&test%5Bfoo%5D=bar", "Sub-object with a length property" );
 
+       params = { "test": [ 1, 2, null ] };
+       assert.equal( jQuery.param( params, false ), "test%5B%5D=1&test%5B%5D=2&test%5B%5D=", "object with array property with null value" );
+
        if ( jQuery.ajaxSettings === settings ) {
                delete jQuery.ajaxSettings;
        } else {