aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/serialize.js5
-rw-r--r--test/unit/serialize.js5
2 files changed, 8 insertions, 2 deletions
diff --git a/src/serialize.js b/src/serialize.js
index a0b948460..9a735fec1 100644
--- a/src/serialize.js
+++ b/src/serialize.js
@@ -58,7 +58,10 @@ jQuery.param = function( a, traditional ) {
add = function( key, 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 );
};
diff --git a/test/unit/serialize.js b/test/unit/serialize.js
index 65d94171c..b87a0aa85 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( 23 );
+ assert.expect( 24 );
var params, settings;
@@ -74,6 +74,9 @@ QUnit.test( "jQuery.param()", function( assert ) {
params = { "param1": null };
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=&param2=", "object with function property that returns null value" );
+
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" );