Skip to content

Commit

Permalink
fix(UrlMatcher): don't decode default values
Browse files Browse the repository at this point in the history
  • Loading branch information
nateabele committed Apr 19, 2014
1 parent b881c72 commit 63607bd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/urlMatcherFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions test/urlMatcherFactorySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down

0 comments on commit 63607bd

Please sign in to comment.