Skip to content

Commit 3d7ce0a

Browse files
DanielNillmgol
authored andcommitted
Serialize: Handle arrays with null values
Closes gh-2436
1 parent 835e921 commit 3d7ce0a

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/serialize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function buildParams( prefix, obj, traditional, add ) {
2828

2929
// Item is non-scalar (array or object), encode its numeric index.
3030
buildParams(
31-
prefix + "[" + ( typeof v === "object" ? i : "" ) + "]",
31+
prefix + "[" + ( jQuery.type( v ) === "object" ? i : "" ) + "]",
3232
v,
3333
traditional,
3434
add

test/unit/serialize.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
QUnit.module( "serialize", { teardown: moduleTeardown } );
22

33
QUnit.test( "jQuery.param()", function( assert ) {
4-
assert.expect( 22 );
4+
assert.expect( 23 );
55

66
var params, settings;
77

@@ -77,6 +77,9 @@ QUnit.test( "jQuery.param()", function( assert ) {
7777
params = { "test": { "length": 3, "foo": "bar" } };
7878
assert.equal( jQuery.param( params, false ), "test%5Blength%5D=3&test%5Bfoo%5D=bar", "Sub-object with a length property" );
7979

80+
params = { "test": [ 1, 2, null ] };
81+
assert.equal( jQuery.param( params, false ), "test%5B%5D=1&test%5B%5D=2&test%5B%5D=", "object with array property with null value" );
82+
8083
if ( jQuery.ajaxSettings === settings ) {
8184
delete jQuery.ajaxSettings;
8285
} else {

0 commit comments

Comments
 (0)