From 251953218c8fa8b0bcb18224e02c8264c37bce64 Mon Sep 17 00:00:00 2001 From: Cody-Nicholson Date: Sat, 30 Jul 2016 21:01:20 -0500 Subject: [PATCH] fix(http): URLSearchParams.clone propagate the QueryEncoder (#9900) --- .../@angular/http/src/url_search_params.ts | 2 +- .../http/test/url_search_params_spec.ts | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/@angular/http/src/url_search_params.ts b/modules/@angular/http/src/url_search_params.ts index 76484d6370..2c09bbb913 100644 --- a/modules/@angular/http/src/url_search_params.ts +++ b/modules/@angular/http/src/url_search_params.ts @@ -89,7 +89,7 @@ export class URLSearchParams { } clone(): URLSearchParams { - var clone = new URLSearchParams(); + var clone = new URLSearchParams('', this.queryEncoder); clone.appendAll(this); return clone; } diff --git a/modules/@angular/http/test/url_search_params_spec.ts b/modules/@angular/http/test/url_search_params_spec.ts index 8a96feed6a..933318c151 100644 --- a/modules/@angular/http/test/url_search_params_spec.ts +++ b/modules/@angular/http/test/url_search_params_spec.ts @@ -127,5 +127,27 @@ export function main() { expect(mapA.getAll('c')).toEqual(['8']); expect(mapA.toString()).toEqual('a=4&a=5&a=6&c=8&b=7'); }); + + it('should support a clone operation via clone()', () => { + var fooQueryEncoder = { + encodeKey(k: string) { return encodeURIComponent(k); }, + encodeValue(v: string) { return encodeURIComponent(v); } + }; + var paramsA = new URLSearchParams('', fooQueryEncoder); + paramsA.set('a', '2'); + paramsA.set('q', '4+'); + paramsA.set('c', '8'); + var paramsB = new URLSearchParams(); + paramsB.set('a', '2'); + paramsB.set('q', '4+'); + paramsB.set('c', '8'); + expect(paramsB.toString()).toEqual('a=2&q=4+&c=8'); + var paramsC = paramsA.clone(); + expect(paramsC.has('a')).toBe(true); + expect(paramsC.has('b')).toBe(false); + expect(paramsC.has('c')).toBe(true); + expect(paramsC.toString()).toEqual('a=2&q=4%2B&c=8'); + }); + }); }