From 3d7ce0a65f0707ff01a851822e57ba80adcff075 Mon Sep 17 00:00:00 2001 From: Daniel Nill Date: Thu, 6 Aug 2015 19:49:14 -0700 Subject: [PATCH] Serialize: Handle arrays with null values Closes gh-2436 --- src/serialize.js | 2 +- test/unit/serialize.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/serialize.js b/src/serialize.js index 76c43ea15..e0839dc09 100644 --- a/src/serialize.js +++ b/src/serialize.js @@ -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 diff --git a/test/unit/serialize.js b/test/unit/serialize.js index 047861530..a64593603 100644 --- a/test/unit/serialize.js +++ b/test/unit/serialize.js @@ -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 { -- 2.39.5