From b9b63f709fa7ea1d9c628adbed4ea152f755f4fd Mon Sep 17 00:00:00 2001 From: Dejan Date: Fri, 20 Oct 2017 12:51:19 +1100 Subject: [PATCH] #298 - Correctly Url Encode arrays in iron-request when content-type is x-www-form-urlencoded --- iron-request.html | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/iron-request.html b/iron-request.html index 0bb3b7f..a4419f2 100644 --- a/iron-request.html +++ b/iron-request.html @@ -436,11 +436,16 @@ } var pieces = []; Object.keys(object).forEach(function(key) { - // TODO(rictic): handle array values here, in a consistent way with - // iron-ajax params. - pieces.push( - this._wwwFormUrlEncodePiece(key) + '=' + - this._wwwFormUrlEncodePiece(object[key])); + if( !Array.isArray(object[key])) { + // Cast to array. + object[key] = [object[key]]; + } + + for( var i = 0; i < object[key].length; i++ ) { + pieces.push( + this._wwwFormUrlEncodePiece(key) + '=' + + this._wwwFormUrlEncodePiece(object[key][i])); + } }, this); return pieces.join('&'); },