From 63607bdbbcb432d3fb37856a1cb3da0cd496804e Mon Sep 17 00:00:00 2001 From: Nate Abele Date: Sat, 19 Apr 2014 17:49:45 -0400 Subject: [PATCH] fix(UrlMatcher): don't decode default values --- src/urlMatcherFactory.js | 4 ++-- test/urlMatcherFactorySpec.js | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/urlMatcherFactory.js b/src/urlMatcherFactory.js index 8d2607ead..7ae6410f4 100644 --- a/src/urlMatcherFactory.js +++ b/src/urlMatcherFactory.js @@ -216,12 +216,12 @@ UrlMatcher.prototype.exec = function (path, searchParams) { for (i = 0; i < nPath; i++) { param = params[i]; cfg = this.params[param]; - values[param] = cfg.type.decode(isDefined(m[i + 1]) ? m[i + 1] : cfg.value); + values[param] = isDefined(m[i + 1]) ? cfg.type.decode(m[i + 1]) : cfg.value; } for (/**/; i < nTotal; i++) { param = params[i]; cfg = this.params[param]; - values[param] = cfg.type.decode(isDefined(searchParams[param]) ? searchParams[param] : cfg.value); + values[param] = isDefined(searchParams[param]) ? cfg.type.decode(searchParams[param]) : cfg.value; } return values; diff --git a/test/urlMatcherFactorySpec.js b/test/urlMatcherFactorySpec.js index 433157bcf..b377b0157 100644 --- a/test/urlMatcherFactorySpec.js +++ b/test/urlMatcherFactorySpec.js @@ -270,8 +270,8 @@ describe("urlMatcherFactory", function () { params: { id: { value: null } } }); expect(m.exec('/users/1138')).toEqual({ id: 1138 }); - expect(m.exec('/users/').id.toString()).toBe("NaN"); - expect(m.exec('/users').id.toString()).toBe("NaN"); + expect(m.exec('/users/').id).toBeNull(); + expect(m.exec('/users').id).toBeNull(); }); it("should correctly match multiple", function() { @@ -281,14 +281,14 @@ describe("urlMatcherFactory", function () { expect(m.exec('/users/1138')).toEqual({ id: 1138, state: null }); expect(m.exec('/users/1138/NY')).toEqual({ id: 1138, state: "NY" }); - expect(m.exec('/users/').id.toString()).toBe("NaN"); + expect(m.exec('/users/').id).toBeNull(); expect(m.exec('/users/').state).toBeNull(); - expect(m.exec('/users').id.toString()).toBe("NaN"); + expect(m.exec('/users').id).toBeNull(); expect(m.exec('/users').state).toBeNull(); expect(m.exec('/users/NY').state).toBe("NY"); - expect(m.exec('/users/NY').id.toString()).toBe("NaN"); + expect(m.exec('/users/NY').id).toBeNull(); }); it("should correctly format with or without values", function() {