diff --git a/modules/@angular/http/src/url_search_params.ts b/modules/@angular/http/src/url_search_params.ts index 3720804d9e..828d833b58 100644 --- a/modules/@angular/http/src/url_search_params.ts +++ b/modules/@angular/http/src/url_search_params.ts @@ -122,8 +122,9 @@ export class URLSearchParams { toString(): string { var paramsList: string[] = []; - this.paramsMap.forEach( - (values, k) => { values.forEach(v => paramsList.push(k + '=' + encodeURIComponent(v))); }); + this.paramsMap.forEach((values, k) => { + values.forEach(v => paramsList.push(encodeURIComponent(k) + '=' + encodeURIComponent(v))); + }); return paramsList.join('&'); } diff --git a/modules/@angular/http/test/url_search_params_spec.ts b/modules/@angular/http/test/url_search_params_spec.ts index d4157dafe1..7c8336b8a4 100644 --- a/modules/@angular/http/test/url_search_params_spec.ts +++ b/modules/@angular/http/test/url_search_params_spec.ts @@ -26,6 +26,15 @@ export function main() { }); + it('should encode special characters in params', () => { + var searchParams = new URLSearchParams(); + searchParams.append('a', '1+1'); + searchParams.append('b c', '2'); + searchParams.append('d%', '3$'); + expect(searchParams.toString()).toEqual('a=1%2B1&b%20c=2&d%25=3%24'); + }); + + it('should support map-like merging operation via setAll()', () => { var mapA = new URLSearchParams('a=1&a=2&a=3&c=8'); var mapB = new URLSearchParams('a=4&a=5&a=6&b=7');