diff --git a/src/urlMatcherFactory.js b/src/urlMatcherFactory.js index 3b733f9ae..ea5071adc 100644 --- a/src/urlMatcherFactory.js +++ b/src/urlMatcherFactory.js @@ -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); diff --git a/test/urlMatcherFactorySpec.js b/test/urlMatcherFactorySpec.js index 3d6cf15d4..aa42f12f3 100755 --- a/test/urlMatcherFactorySpec.js +++ b/test/urlMatcherFactorySpec.js @@ -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");