From 79af2badcb087881e3fd600f6ae5bf3f86a2daf8 Mon Sep 17 00:00:00 2001 From: Tom Davis Date: Fri, 14 Sep 2012 17:42:39 -0400 Subject: fix($http): config.param should expand array values properly Today, calling e.g. $http(url, { params: { a: [1,2,3] } }) results in a query string like "?a=%5B1%2C2%2C3%5D" which is undesirable. This commit enhances buildURL to createa query string like "?a=1&a=2&a=3". BREAKING CHANGE: if the server relied on the buggy behavior then either the backend should be fixed or a simple serialization of the array should be done on the client before calling the $http service. Closes #1363 --- src/ng/http.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ng/http.js b/src/ng/http.js index aa0eca74..9b133476 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -758,10 +758,15 @@ function $HttpProvider() { var parts = []; forEachSorted(params, function(value, key) { if (value == null || value == undefined) return; - if (isObject(value)) { - value = toJson(value); - } - parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(value)); + if (!isArray(value)) value = [value]; + + forEach(value, function(v) { + if (isObject(v)) { + v = toJson(v); + } + parts.push(encodeURIComponent(key) + '=' + + encodeURIComponent(v)); + }); }); return url + ((url.indexOf('?') == -1) ? '?' : '&') + parts.join('&'); } -- cgit v1.2.3