mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Serialize: Treat literal and function-returned null/undefined the same
Fixes gh-3005 Closes gh-3007
This commit is contained in:
parent
5d20a3c3f1
commit
9fdbdd393a
@ -58,7 +58,10 @@ jQuery.param = function( a, traditional ) {
|
|||||||
add = function( key, value ) {
|
add = function( key, value ) {
|
||||||
|
|
||||||
// If value is a function, invoke it and return its value
|
// If value is a function, invoke it and return its value
|
||||||
value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
|
value = jQuery.isFunction( value ) ? value() : value;
|
||||||
|
if ( value == null ) {
|
||||||
|
value = "";
|
||||||
|
}
|
||||||
s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
|
s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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, settings;
|
var params, settings;
|
||||||
|
|
||||||
@ -74,6 +74,9 @@ QUnit.test( "jQuery.param()", function( assert ) {
|
|||||||
params = { "param1": null };
|
params = { "param1": null };
|
||||||
assert.equal( jQuery.param( params, false ), "param1=", "Make sure that null params aren't traversed." );
|
assert.equal( jQuery.param( params, false ), "param1=", "Make sure that null params aren't traversed." );
|
||||||
|
|
||||||
|
params = { "param1": function() {}, "param2": function() { return null; } };
|
||||||
|
assert.equal( jQuery.param( params, false ), "param1=¶m2=", "object with function property that returns null value" );
|
||||||
|
|
||||||
params = { "test": { "length": 3, "foo": "bar" } };
|
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" );
|
assert.equal( jQuery.param( params, false ), "test%5Blength%5D=3&test%5Bfoo%5D=bar", "Sub-object with a length property" );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user