@@ -113,22 +113,27 @@ var Form = {
113113 accumulator = function ( result , key , value ) {
114114 if ( key in result ) {
115115 if ( ! Object . isArray ( result [ key ] ) ) result [ key ] = [ result [ key ] ] ;
116- result [ key ] . push ( value ) ;
116+ result [ key ] = result [ key ] . concat ( value ) ;
117117 } else result [ key ] = value ;
118118 return result ;
119119 } ;
120120 } else {
121121 initial = '' ;
122- accumulator = function ( result , key , value ) {
123- // Normalize newlines as \r\n because the HTML spec says newlines should
124- // be encoded as CRLFs.
125- value = value . gsub ( / ( \r ) ? \n / , '\r\n' ) ;
126- value = encodeURIComponent ( value ) ;
127- // Likewise, according to the spec, spaces should be '+' rather than
128- // '%20'.
129- value = value . gsub ( / % 2 0 / , '+' ) ;
130- return result + ( result ? '&' : '' ) + encodeURIComponent ( key ) + '=' + value ;
131- }
122+ accumulator = function ( result , key , values ) {
123+ if ( ! Object . isArray ( values ) ) { values = [ values ] ; }
124+ if ( ! values . length ) { return result ; }
125+ // According to the spec, spaces should be '+' rather than '%20'.
126+ var encodedKey = encodeURIComponent ( key ) . gsub ( / % 2 0 / , '+' ) ;
127+ return result + ( result ? "&" : "" ) + values . map ( function ( value ) {
128+ // Normalize newlines as \r\n because the HTML spec says newlines should
129+ // be encoded as CRLFs.
130+ value = value . gsub ( / ( \r ) ? \n / , '\r\n' ) ;
131+ value = encodeURIComponent ( value ) ;
132+ // According to the spec, spaces should be '+' rather than '%20'.
133+ value = value . gsub ( / % 2 0 / , '+' ) ;
134+ return encodedKey + "=" + value ;
135+ } ) . join ( "&" ) ;
136+ } ;
132137 }
133138
134139 return elements . inject ( initial , function ( result , element ) {
0 commit comments