Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/isomorphic/urlMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@ export function globToRegexPattern(glob: string): string {

switch (c) {
case '{':
if (inGroup)
throw new Error(`Invalid glob pattern "${glob}": nested '{' is not supported`);
inGroup = true;
tokens.push('(');
break;
case '}':
if (!inGroup)
throw new Error(`Invalid glob pattern "${glob}": unmatched '}'`);
inGroup = false;
tokens.push(')');
break;
Expand All @@ -74,6 +78,8 @@ export function globToRegexPattern(glob: string): string {
tokens.push(escapedChars.has(c) ? '\\' + c : c);
}
}
if (inGroup)
throw new Error(`Invalid glob pattern "${glob}": unmatched '{'`);
tokens.push('$');
return tokens.join('');
}
Expand Down
8 changes: 8 additions & 0 deletions tests/page/interception.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ it('should work with glob', async () => {
expect(urlMatches(undefined, `${prefix}:blank`, `${prefix}:*`)).toBeTruthy();
expect(urlMatches(undefined, `not${prefix}:blank`, `${prefix}:*`)).toBeFalsy();
}

// Unbalanced braces must throw early with a descriptive error.
expect(() => globToRegexPattern('{foo')).toThrow(`Invalid glob pattern "{foo": unmatched '{'`);
expect(() => globToRegexPattern('}foo')).toThrow(`Invalid glob pattern "}foo": unmatched '}'`);
expect(() => globToRegexPattern('**/*.png?{')).toThrow(`Invalid glob pattern "**/*.png?{": unmatched '{'`);
expect(() => globToRegexPattern('https://example.com/{a')).toThrow(`Invalid glob pattern "https://example.com/{a": unmatched '{'`);
expect(() => globToRegexPattern('{a,b')).toThrow(`Invalid glob pattern "{a,b": unmatched '{'`);
expect(() => globToRegexPattern('{a,{b}}')).toThrow(`Invalid glob pattern "{a,{b}}": nested '{' is not supported`);
});

it('should intercept by glob', async function({ page, server, isAndroid }) {
Expand Down