aboutsummaryrefslogtreecommitdiffstats
path: root/src/ng
diff options
context:
space:
mode:
authorTom Davis2012-09-14 17:42:39 -0400
committerIgor Minar2012-11-24 22:26:23 +0100
commit79af2badcb087881e3fd600f6ae5bf3f86a2daf8 (patch)
treee8a09cdb42f371e4f6c15dbb69c2faf7c82e0f38 /src/ng
parent610927d77b77700c5c61accd503a2af0fa51cfe6 (diff)
downloadangular.js-79af2badcb087881e3fd600f6ae5bf3f86a2daf8.tar.bz2
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
Diffstat (limited to 'src/ng')
-rw-r--r--src/ng/http.js13
1 files changed, 9 insertions, 4 deletions
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('&');
}