diff --git a/src/ng/http.js b/src/ng/http.js index 443daf83a696..1cf0e683cb74 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -966,16 +966,17 @@ function $HttpProvider() { function buildUrl(url, params) { if (!params) return url; - var parts = []; + var parts = [], valueIsArray; forEachSorted(params, function(value, key) { if (value == null || value == undefined) return; - if (!isArray(value)) value = [value]; + valueIsArray = isArray(value); + if (!valueIsArray) value = [value]; forEach(value, function(v) { if (isObject(v)) { v = toJson(v); } - parts.push(encodeUriQuery(key) + '=' + + parts.push(encodeUriQuery(key) + (valueIsArray ? '[]=' : '=') + encodeUriQuery(v)); }); }); diff --git a/test/ng/httpSpec.js b/test/ng/httpSpec.js index d3653a67ee7d..60f6ebc3dc4c 100644 --- a/test/ng/httpSpec.js +++ b/test/ng/httpSpec.js @@ -438,11 +438,17 @@ describe('$http', function() { it('should expand arrays in params map', inject(function($httpBackend, $http) { - $httpBackend.expect('GET', '/url?a=1&a=2&a=3').respond(''); + $httpBackend.expect('GET', '/url?a[]=1&a[]=2&a[]=3').respond(''); $http({url: '/url', params: {a: [1,2,3]}, method: 'GET'}); })); + it('should expand short arrays in params map', inject(function($httpBackend, $http) { + $httpBackend.expect('GET', '/url?a[]=1').respond(''); + $http({url: '/url', params: {a: [1]}, method: 'GET'}); + })); + + it('should not encode @ in url params', function() { //encodeURIComponent is too agressive and doesn't follow http://www.ietf.org/rfc/rfc3986.txt //with regards to the character set (pchar) allowed in path segments diff --git a/test/ngResource/resourceSpec.js b/test/ngResource/resourceSpec.js index c49ac9e0acfe..7601754214e1 100644 --- a/test/ngResource/resourceSpec.js +++ b/test/ngResource/resourceSpec.js @@ -139,7 +139,7 @@ describe("resource", function() { it('should encode array params', function() { var R = $resource('/Path/:a'); - $httpBackend.expect('GET', '/Path/doh&foo?bar=baz1&bar=baz2').respond('{}'); + $httpBackend.expect('GET', '/Path/doh&foo?bar[]=baz1&bar[]=baz2').respond('{}'); R.get({a: 'doh&foo', bar: ['baz1', 'baz2']}); });