diff --git a/src/urlMatcherFactory.js b/src/urlMatcherFactory.js index 30ff0be0b..1c37c9f18 100644 --- a/src/urlMatcherFactory.js +++ b/src/urlMatcherFactory.js @@ -920,8 +920,6 @@ function $UrlMatcherFactory() { type = getType(config, type, location); var arrayMode = getArrayMode(); type = arrayMode ? type.$asArray(arrayMode, location === "search") : type; - if (type.name === "string" && !arrayMode && location === "path" && config.value === undefined) - config.value = ""; // for 0.2.x; in 0.3.0+ do not automatically default to "" var isOptional = config.value !== undefined; var squash = getSquashPolicy(config, isOptional); var replace = getReplace(config, arrayMode, isOptional, squash); diff --git a/test/urlMatcherFactorySpec.js b/test/urlMatcherFactorySpec.js index 003d86edd..cd3e53172 100755 --- a/test/urlMatcherFactorySpec.js +++ b/test/urlMatcherFactorySpec.js @@ -156,7 +156,22 @@ describe("UrlMatcher", function () { var m = new UrlMatcher('/users/:id/details/{type}/{repeat:[0-9]+}?from&to'); expect(m.exec('/users/123/details/what/thisShouldBeDigits', {})).toBeNull(); }); + + it("should not use optional regexp for '/'", function () { + var m = new UrlMatcher('/{language:(?:fr|en|de)}'); + expect(m.exec('/', {})).toBeNull(); + }); + + it("should work with empty default value", function () { + var m = new UrlMatcher('/foo/:str', { params: { str: { value: "" } } }); + expect(m.exec('/foo/', {})).toEqual({ str: "" }); + }); + it("should work with empty default value for regex", function () { + var m = new UrlMatcher('/foo/{param:(?:foo|bar|)}', { params: { param: { value: "" } } }); + expect(m.exec('/foo/', {})).toEqual({ param: "" }); + }); + it("should treat the URL as already decoded and does not decode it further", function () { expect(new UrlMatcher('/users/:id').exec('/users/100%25', {})).toEqual({ id: '100%25'}); });