From 38704fd5212dd396e074d13c6861e8c688c3d21c Mon Sep 17 00:00:00 2001 From: Christian Liebel Date: Wed, 1 Jul 2015 11:24:52 +0200 Subject: [PATCH 1/2] fix(urlMatcherFactory): Decode slashes in string routes Slashes in string routes now get decoded (they were only encoded before). Related test was fixed. --- src/urlMatcherFactory.js | 5 +++-- test/urlMatcherFactorySpec.js | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/urlMatcherFactory.js b/src/urlMatcherFactory.js index bf116f027..ae8215724 100644 --- a/src/urlMatcherFactory.js +++ b/src/urlMatcherFactory.js @@ -568,8 +568,9 @@ function $UrlMatcherFactory() { $$UMFP = this; var isCaseInsensitive = false, isStrictMode = true, defaultSquashPolicy = false; + var slashReplacement = "%2F"; - function valToString(val) { return val != null ? val.toString().replace(/\//g, "%2F") : val; } + function valToString(val) { return val != null ? val.toString().replace(/\//g, slashReplacement) : val; } function valFromString(val) { return val != null ? val.toString().replace(/%2F/g, "/") : val; } var $types = {}, enqueue = true, typeQueue = [], injector, defaultTypes = { @@ -578,7 +579,7 @@ function $UrlMatcherFactory() { decode: valFromString, // TODO: in 1.0, make string .is() return false if value is undefined/null by default. // In 0.2.x, string params are optional by default for backwards compat - is: function(val) { return val == null || !isDefined(val) || typeof val === "string"; }, + is: function(val) { return (val == null || !isDefined(val) || typeof val === "string") && (val.toString().indexOf(slashReplacement) === -1); }, pattern: /[^/]*/ }, int: { diff --git a/test/urlMatcherFactorySpec.js b/test/urlMatcherFactorySpec.js index 8b0c1b678..aa51456a9 100755 --- a/test/urlMatcherFactorySpec.js +++ b/test/urlMatcherFactorySpec.js @@ -65,6 +65,7 @@ describe("UrlMatcher", function () { var matcher = new UrlMatcher('/:foo'); expect(matcher.format({ foo: "/" })).toBe('/%252F'); expect(matcher.format({ foo: "//" })).toBe('/%252F%252F'); + expect(matcher.exec('/hello%2Fworld')).toEqual({ foo: 'hello/world' }); }); describe("snake-case parameters", function() { From 0b903627b8886baddab5c3d538dd17bcc7843195 Mon Sep 17 00:00:00 2001 From: Christian Liebel Date: Fri, 3 Jul 2015 20:02:07 +0200 Subject: [PATCH 2/2] fix(urlMatcherFactory): Fixed a case where val can be null Kudos to @pjotrd #2071 --- src/urlMatcherFactory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/urlMatcherFactory.js b/src/urlMatcherFactory.js index ae8215724..67ffb357b 100644 --- a/src/urlMatcherFactory.js +++ b/src/urlMatcherFactory.js @@ -579,7 +579,7 @@ function $UrlMatcherFactory() { decode: valFromString, // TODO: in 1.0, make string .is() return false if value is undefined/null by default. // In 0.2.x, string params are optional by default for backwards compat - is: function(val) { return (val == null || !isDefined(val) || typeof val === "string") && (val.toString().indexOf(slashReplacement) === -1); }, + is: function(val) { return val == null || !isDefined(val) || (isString(val) && val.indexOf(slashReplacement) === -1); }, pattern: /[^/]*/ }, int: {