Bug Tracker

Ticket #2726: param.diff

File param.diff, 1.7 kB (added by flesler, 8 months ago)

This is the change, but I think I won't be able to apply it as many people/servers don't expect this to happen.

  • src/ajax.js

     
    479479    param: function( a ) { 
    480480        var s = []; 
    481481 
     482        function add( key, value ){ 
     483            s[s.length] = key + "=" + encodeURIComponent( value ); 
     484        }; 
     485 
    482486        // If an array was passed in, assume that it is an array 
    483487        // of form elements 
    484488        if ( a.constructor == Array || a.jquery ) 
    485489            // Serialize the form elements 
    486490            jQuery.each( a, function(){ 
    487                 s.push( encodeURIComponent(this.name) + "=" + encodeURIComponent( this.value ) ); 
     491                add( encodeURIComponent(this.name), this.value ); 
    488492            }); 
    489493 
    490494        // Otherwise, assume that it's an object of key/value pairs 
    491495        else 
    492496            // Serialize the key/values 
    493             for ( var j in a ) 
    494                 // If the value is an array then the key names need to be repeated 
    495                 if ( a[j] && a[j].constructor == Array ) 
    496                     jQuery.each( a[j], function(){ 
    497                         s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) ); 
     497            for ( var j in a ){ 
     498                var obj = a[j]; 
     499                 
     500                // Encode it, but don't encode the squared brackets afterwards 
     501                j = encodeURIComponent(j); 
     502                 
     503                // If the value is an array or a map, generate name[key]=value 
     504                if ( obj && typeof obj == 'object' ) 
     505                    jQuery.each( obj, function( key, v ){ 
     506                        var name = j; 
     507                        // Don't break name[]=v1&name[]=v2 ... 
     508                        if( j.indexOf('[]') == -1 ) 
     509                            name += '['+k+']'; 
     510                        add( name , v ); 
    498511                    }); 
    499512                else 
    500                     s.push( encodeURIComponent(j) + "=" + encodeURIComponent( jQuery.isFunction(a[j]) ? a[j]() : a[j] ) ); 
     513                    add( j, jQuery.isFunction(obj) ? obj() : obj ); 
     514            } 
    501515 
    502516        // Return the resulting serialization 
    503517        return s.join("&").replace(/%20/g, "+");