Skip to content

$.param() returns "null" and "undefined" literal if attribute is function #3005

@jtrumbull

Description

@jtrumbull
var param = $.param({
  a: function () {},
  b: function () { return null; }
});

Will result in a=undefined&b=null

jsfiddle

The value == null check on Line 61 should happen after the ternary statement, since both value and the result of value() can be null. i.e.

        add = function( key, value ) {

            // If value is a function, invoke it and return its value
            value = jQuery.isFunction( value ) ? value() : value;
            value = value == null ? "" : value;
            s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
        };

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions