Skip to content

Commit

Permalink
feat(UrlMatcher): Add param only type names
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva committed Oct 6, 2015
1 parent 6f723a5 commit 6a371f9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/urlMatcherFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,8 @@ function $UrlMatcherFactory() {
}

function getType(config, urlType, location) {
if (config.type && urlType) throw new Error("Param '"+id+"' has two type configurations.");
if (config.type && urlType.name !== 'string') throw new Error("Param '"+id+"' has two type configurations.");
if (config.type && urlType.name === 'string' && $types[config.type]) return $types[config.type];
if (urlType) return urlType;
if (!config.type) return (location === "config" ? $types.any : $types.string);
return config.type instanceof Type ? config.type : new Type(config.type);
Expand Down
15 changes: 15 additions & 0 deletions test/urlMatcherFactorySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,21 @@ describe("urlMatcherFactory", function () {
expect(m.format({ foo: 5, flag: true })).toBe("/5/1");
});

it("should match types named only in params", function () {
var m = new UrlMatcher("/{foo}/{flag}", {
params: {
foo: {
type: 'int'
},
flag: {
type: 'bool'
}
}
});
expect(m.exec("/1138/1")).toEqual({ foo: 1138, flag: true });
expect(m.format({ foo: 5, flag: true })).toBe("/5/1");
});

it("should encode/decode dates", function () {
var m = new UrlMatcher("/calendar/{date:date}"),
result = m.exec("/calendar/2014-03-26");
Expand Down

0 comments on commit 6a371f9

Please sign in to comment.