Skip to content

Commit 5b11ce0

Browse files
DmitryGoncharchristopherthielen
authored andcommitted
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 angular-ui/ui-router#3432
1 parent ddfc1dc commit 5b11ce0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/url/urlMatcher.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export class UrlMatcher {
160160
const matchDetails = (m: RegExpExecArray, isSearch: boolean) => {
161161
// IE[78] returns '' for unmatched groups instead of null
162162
let id = m[2] || m[3];
163-
let regexp = isSearch ? m[4] : m[4] || (m[1] === '*' ? '.*' : null);
163+
let regexp = isSearch ? m[4] : m[4] || (m[1] === '*' ? '[\\s\\S]*' : null);
164164

165165
const makeRegexpType = (regexp) => inherit(paramTypes.type(isSearch ? "query" : "path"), {
166166
pattern: new RegExp(regexp, this.config.caseInsensitive ? 'i' : undefined)

test/urlMatcherFactorySpec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ describe("UrlMatcher", function () {
112112
expect(m.exec('/document/', {})).toEqual({ path: '' });
113113
});
114114

115+
it("should capture catch-all parameters in multiline url", function () {
116+
var m = $umf.compile('/document/*path');
117+
expect(m.exec('/document/a/b/c\r\n/d', {})).toEqual({ path: 'a/b/c\r\n/d' });
118+
expect(m.exec('/document/\r\na/b\r\n/c', {})).toEqual({ path: '\r\na/b\r\n/c' });
119+
expect(m.exec('/document/a/b\r\n\r\n/c', {})).toEqual({ path: 'a/b\r\n\r\n/c' });
120+
expect(m.exec('/document/a/\rb/c\n', {})).toEqual({ path: 'a/\rb/c\n' });
121+
expect(m.exec('/document/\r\n', {})).toEqual({ path: '\r\n' });
122+
});
123+
115124
it("should use the optional regexp with curly brace placeholders", function () {
116125
var m = $umf.compile('/users/:id/details/{type}/{repeat:[0-9]+}?from&to');
117126
expect(m.exec('/users/123/details/what/thisShouldBeDigits', {})).toBeNull();

0 commit comments

Comments
 (0)