Skip to content

Commit

Permalink
fix(http): URLSearchParams.clone propagate the QueryEncoder (#9900)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cody-Nicholson authored and vicb committed Jul 31, 2016
1 parent 0d6cc17 commit 2519532
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/@angular/http/src/url_search_params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class URLSearchParams {
}

clone(): URLSearchParams {
var clone = new URLSearchParams();
var clone = new URLSearchParams('', this.queryEncoder);
clone.appendAll(this);
return clone;
}
Expand Down
22 changes: 22 additions & 0 deletions modules/@angular/http/test/url_search_params_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

});
}

0 comments on commit 2519532

Please sign in to comment.