mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Serialize: jQuery.param: return empty string when given null/undefined
Fixes gh-2633 Close gh-4108
This commit is contained in:
parent
4f3b8f0d0b
commit
0645099e02
@ -70,6 +70,10 @@ jQuery.param = function( a, traditional ) {
|
|||||||
encodeURIComponent( value == null ? "" : value );
|
encodeURIComponent( value == null ? "" : value );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if ( a == null ) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
// If an array was passed in, assume that it is an array of form elements.
|
// If an array was passed in, assume that it is an array of form elements.
|
||||||
if ( Array.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
|
if ( Array.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
QUnit.module( "serialize", { teardown: moduleTeardown } );
|
QUnit.module( "serialize", { teardown: moduleTeardown } );
|
||||||
|
|
||||||
QUnit.test( "jQuery.param()", function( assert ) {
|
QUnit.test( "jQuery.param()", function( assert ) {
|
||||||
assert.expect( 23 );
|
assert.expect( 24 );
|
||||||
|
|
||||||
var params;
|
var params;
|
||||||
|
|
||||||
@ -72,6 +72,9 @@ QUnit.test( "jQuery.param()", function( assert ) {
|
|||||||
|
|
||||||
params = { "test": [ 1, 2, null ] };
|
params = { "test": [ 1, 2, null ] };
|
||||||
assert.equal( jQuery.param( params ), "test%5B%5D=1&test%5B%5D=2&test%5B%5D=", "object with array property with null value" );
|
assert.equal( jQuery.param( params ), "test%5B%5D=1&test%5B%5D=2&test%5B%5D=", "object with array property with null value" );
|
||||||
|
|
||||||
|
params = undefined;
|
||||||
|
assert.equal( jQuery.param( params ), "", "jQuery.param( undefined ) === empty string" );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( "jQuery.param() not affected by ajaxSettings", function( assert ) {
|
QUnit.test( "jQuery.param() not affected by ajaxSettings", function( assert ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user