From 508c7c8ff412f4b75ae0fa2a0404c4e8ebc708cb Mon Sep 17 00:00:00 2001 From: Dmitry Gonchar Date: Fri, 16 Jun 2017 06:58:15 +0300 Subject: [PATCH] feat(urlMatcher): add support for multiline urls urls with \r or \n symbols in them (%0D or %0A when encoded) are matched with catch-all syntax closes https://github.com/angular-ui/ui-router/issues/3432 --- src/url/urlMatcher.ts | 2 +- test/urlMatcherFactorySpec.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/url/urlMatcher.ts b/src/url/urlMatcher.ts index bb39999f..1267c8a2 100644 --- a/src/url/urlMatcher.ts +++ b/src/url/urlMatcher.ts @@ -160,7 +160,7 @@ export class UrlMatcher { const matchDetails = (m: RegExpExecArray, isSearch: boolean) => { // IE[78] returns '' for unmatched groups instead of null let id = m[2] || m[3]; - let regexp = isSearch ? m[4] : m[4] || (m[1] === '*' ? '.*' : null); + let regexp = isSearch ? m[4] : m[4] || (m[1] === '*' ? '[\\s\\S]*' : null); const makeRegexpType = (regexp) => inherit(paramTypes.type(isSearch ? "query" : "path"), { pattern: new RegExp(regexp, this.config.caseInsensitive ? 'i' : undefined) diff --git a/test/urlMatcherFactorySpec.ts b/test/urlMatcherFactorySpec.ts index 9b183a44..5339715c 100644 --- a/test/urlMatcherFactorySpec.ts +++ b/test/urlMatcherFactorySpec.ts @@ -112,6 +112,15 @@ describe("UrlMatcher", function () { expect(m.exec('/document/', {})).toEqual({ path: '' }); }); + it("should capture catch-all parameters in multiline url", function () { + var m = $umf.compile('/document/*path'); + expect(m.exec('/document/a/b/c\r\n/d', {})).toEqual({ path: 'a/b/c\r\n/d' }); + expect(m.exec('/document/\r\na/b\r\n/c', {})).toEqual({ path: '\r\na/b\r\n/c' }); + expect(m.exec('/document/a/b\r\n\r\n/c', {})).toEqual({ path: 'a/b\r\n\r\n/c' }); + expect(m.exec('/document/a/\rb/c\n', {})).toEqual({ path: 'a/\rb/c\n' }); + expect(m.exec('/document/\r\n', {})).toEqual({ path: '\r\n' }); + }); + it("should use the optional regexp with curly brace placeholders", function () { var m = $umf.compile('/users/:id/details/{type}/{repeat:[0-9]+}?from&to'); expect(m.exec('/users/123/details/what/thisShouldBeDigits', {})).toBeNull();