🌐 AI搜索 & 代理 主页
Skip to content

Commit 0645099

Browse files
authored
Serialize: jQuery.param: return empty string when given null/undefined
Fixes gh-2633 Close gh-4108
1 parent 4f3b8f0 commit 0645099

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/serialize.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ jQuery.param = function( a, traditional ) {
7070
encodeURIComponent( value == null ? "" : value );
7171
};
7272

73+
if ( a == null ) {
74+
return "";
75+
}
76+
7377
// If an array was passed in, assume that it is an array of form elements.
7478
if ( Array.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
7579

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( 23 );
4+
assert.expect( 24 );
55

66
var params;
77

@@ -72,6 +72,9 @@ QUnit.test( "jQuery.param()", function( assert ) {
7272

7373
params = { "test": [ 1, 2, null ] };
7474
assert.equal( jQuery.param( params ), "test%5B%5D=1&test%5B%5D=2&test%5B%5D=", "object with array property with null value" );
75+
76+
params = undefined;
77+
assert.equal( jQuery.param( params ), "", "jQuery.param( undefined ) === empty string" );
7578
} );
7679

7780
QUnit.test( "jQuery.param() not affected by ajaxSettings", function( assert ) {

0 commit comments

Comments
 (0)