diff --git a/src/urlMatcherFactory.js b/src/urlMatcherFactory.js index afe6f5d52..2eacfffda 100644 --- a/src/urlMatcherFactory.js +++ b/src/urlMatcherFactory.js @@ -342,7 +342,11 @@ UrlMatcher.prototype.format = function (values) { if (squash === false) { if (encoded != null) { if (isArray(encoded)) { - result += map(encoded, encodeDashes).join("-"); + if (param.type.name == 'path') { + result += map(encoded, encodeURIComponent).join("/"); + } else { + result += map(encoded, encodeDashes).join("-"); + } } else { result += encodeURIComponent(encoded); } @@ -620,6 +624,14 @@ function $UrlMatcherFactory() { equals: angular.equals, pattern: /[^/]*/ }, + path: { + encode: function(val) { + return val.split('/'); + }, + decode: angular.identity, + is: regexpMatches, + pattern: /.*/ + }, any: { // does not encode/decode encode: angular.identity, decode: angular.identity, diff --git a/test/urlMatcherFactorySpec.js b/test/urlMatcherFactorySpec.js index 673fee234..c1be0a866 100755 --- a/test/urlMatcherFactorySpec.js +++ b/test/urlMatcherFactorySpec.js @@ -530,6 +530,17 @@ describe("urlMatcherFactory", function () { expect(m.exec("/state/" + json1 + "/" + json2)).toEqual(params); }); + it("should encode/decode path parameters without encoding the slashes", function () { + var m = new UrlMatcher("/{path:path}"); + expect(m.exec("/some/path")).toEqual({ path: 'some/path' }); + expect(m.format({ path: 'some/path' })).toBe('/some/path'); + }); + + it("should encode path parameters with encoding of the path parameter components", function () { + var m = new UrlMatcher("/{path:path}"); + expect(m.format({ path: 'some /path' })).toBe('/some%20/path'); + }); + it("should not match invalid typed parameter values", function() { var m = new UrlMatcher('/users/{id:int}');