diff --git a/src/params/paramTypes.ts b/src/params/paramTypes.ts index 0f9f4f259..9137af5f2 100644 --- a/src/params/paramTypes.ts +++ b/src/params/paramTypes.ts @@ -10,8 +10,8 @@ import {ParamTypeDefinition} from "./interface"; // If the slashes are simply URLEncoded, the browser can choose to pre-decode them, // and bidirectional encoding/decoding fails. // Tilde was chosen because it's not a RFC 3986 section 2.2 Reserved Character -function valToString(val: any) { return val != null ? val.toString().replace(/~/g, "~~").replace(/\//g, "~2F") : val; } -function valFromString(val: string) { return val != null ? val.toString().replace(/~2F/g, "/").replace(/~~/g, "~") : val; } +function valToString(val: any) { return val != null ? val.toString().replace(/(~|\/)/g, m => ({'~':'~~', '/':'~2F'}[m])) : val; } +function valFromString(val: string) { return val != null ? val.toString().replace(/(~~|~2F)/g, m => ({'~~':'~', '~2F':'/'}[m])) : val; } export class ParamTypes { types: any; diff --git a/test/ng1/urlMatcherFactorySpec.js b/test/ng1/urlMatcherFactorySpec.js index 3fd4f8dd5..46c2fe38e 100755 --- a/test/ng1/urlMatcherFactorySpec.js +++ b/test/ng1/urlMatcherFactorySpec.js @@ -111,9 +111,11 @@ describe("UrlMatcher", function () { expect(matcher1.format({ foo: "abc" })).toBe('/abc'); expect(matcher1.format({ foo: "~abc" })).toBe('/~~abc'); + expect(matcher1.format({ foo: "~2F" })).toBe('/~~2F'); expect(matcher1.exec('/abc').foo).toBe("abc"); expect(matcher1.exec('/~~abc').foo).toBe("~abc"); + expect(matcher1.exec('/~~2F').foo).toBe("~2F"); }); describe("snake-case parameters", function() {