From 995a9e0cf89864b22d50d85db0e196057a9e4b66 Mon Sep 17 00:00:00 2001 From: Brian Yarger Date: Tue, 5 Jan 2016 22:34:10 -0700 Subject: [PATCH] fix(router): fix incorrect url param value coercion of 1 to true seriliazeParams is coercing a value of 1 to true, which causes the value to be completey dropped. Change the test from double equals to triple equals to prevent this from happening. Closes #5346 Closes #6286 --- modules/angular2/src/router/url_parser.ts | 2 +- modules/angular2/test/router/router_spec.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/angular2/src/router/url_parser.ts b/modules/angular2/src/router/url_parser.ts index 64ba1c8b3d..2726dc1e37 100644 --- a/modules/angular2/src/router/url_parser.ts +++ b/modules/angular2/src/router/url_parser.ts @@ -206,7 +206,7 @@ export function serializeParams(paramMap: {[key: string]: any}): string[] { var params = []; if (isPresent(paramMap)) { StringMapWrapper.forEach(paramMap, (value, key) => { - if (value == true) { + if (value === true) { params.push(key); } else { params.push(key + '=' + value); diff --git a/modules/angular2/test/router/router_spec.ts b/modules/angular2/test/router/router_spec.ts index 164213b6c7..96b61eac2e 100644 --- a/modules/angular2/test/router/router_spec.ts +++ b/modules/angular2/test/router/router_spec.ts @@ -220,6 +220,15 @@ export function main() { expect(path).toEqual('hi/how/are/you?name=brad'); }); + it('should preserve the number 1 as a query string value', () => { + router.config( + [new Route({path: '/hi/how/are/you', component: DummyComponent, name: 'GreetingUrl'})]); + + var instruction = router.generate(['/GreetingUrl', {'name': 1}]); + var path = stringifyInstruction(instruction); + expect(path).toEqual('hi/how/are/you?name=1'); + }); + it('should serialize parameters that are not part of the route definition as query string params', () => { router.config([