diff --git a/src/urlMatcherFactory.js b/src/urlMatcherFactory.js index a155d1975..ec9d4023d 100644 --- a/src/urlMatcherFactory.js +++ b/src/urlMatcherFactory.js @@ -561,8 +561,8 @@ function $UrlMatcherFactory() { var isCaseInsensitive = false, isStrictMode = true, defaultSquashPolicy = false; - function valToString(val) { return val != null ? val.toString().replace("/", "%2F") : val; } - function valFromString(val) { return val != null ? val.toString().replace("%2F", "/") : val; } + function valToString(val) { return val != null ? val.toString().replace(/\//g, "%2F") : val; } + function valFromString(val) { return val != null ? val.toString().replace(/%2F/g, "/") : val; } function angularEquals(left, right) { return angular.equals(left, right); } // TODO: in 1.0, make string .is() return false if value is undefined by default. // function regexpMatches(val) { /*jshint validthis:true */ return isDefined(val) && this.pattern.test(val); } diff --git a/test/urlMatcherFactorySpec.js b/test/urlMatcherFactorySpec.js index d92e4f462..8a43a4c24 100644 --- a/test/urlMatcherFactorySpec.js +++ b/test/urlMatcherFactorySpec.js @@ -61,6 +61,12 @@ describe("UrlMatcher", function () { expect(matcher.format(array)).toBe('/?foo=bar&foo=baz'); }); + it("should encode and decode slashes in parameter values", function () { + var matcher = new UrlMatcher('/:foo'); + expect(matcher.format({ foo: "/" })).toBe('/%252F'); + expect(matcher.format({ foo: "//" })).toBe('/%252F%252F'); + }); + describe("snake-case parameters", function() { it("should match if properly formatted", function() { var matcher = new UrlMatcher('/users/?from&to&snake-case&snake-case-triple');