Skip to content

Commit 995a9e0

Browse files
bkyargeralexeagle
authored andcommitted
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
1 parent b55f176 commit 995a9e0

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

modules/angular2/src/router/url_parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export function serializeParams(paramMap: {[key: string]: any}): string[] {
206206
var params = [];
207207
if (isPresent(paramMap)) {
208208
StringMapWrapper.forEach(paramMap, (value, key) => {
209-
if (value == true) {
209+
if (value === true) {
210210
params.push(key);
211211
} else {
212212
params.push(key + '=' + value);

modules/angular2/test/router/router_spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,15 @@ export function main() {
220220
expect(path).toEqual('hi/how/are/you?name=brad');
221221
});
222222

223+
it('should preserve the number 1 as a query string value', () => {
224+
router.config(
225+
[new Route({path: '/hi/how/are/you', component: DummyComponent, name: 'GreetingUrl'})]);
226+
227+
var instruction = router.generate(['/GreetingUrl', {'name': 1}]);
228+
var path = stringifyInstruction(instruction);
229+
expect(path).toEqual('hi/how/are/you?name=1');
230+
});
231+
223232
it('should serialize parameters that are not part of the route definition as query string params',
224233
() => {
225234
router.config([

0 commit comments

Comments
 (0)