fix(http): add search param escaping for keys (#9166)

This commit is contained in:
Dmitry Zamula 2016-06-23 04:23:15 +03:00 committed by Rob Wormald
parent 8899b83927
commit a5f2e205ef
2 changed files with 12 additions and 2 deletions

View File

@ -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('&');
}

View File

@ -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');