Description
When a glob pattern with unbalanced { or } is passed to page.route(), the internal
globToRegexPattern() emits an unterminated regex group. When a real HTTP request is made,
new RegExp(pattern) throws SyntaxError: Invalid regular expression inside the route
matcher — silently aborting the request. The page never loads and navigation times out with
net::ERR_ABORTED.
Minimal repro
import { test } from "@playwright/test";
import { createServer } from "http";
test("unbalanced brace in route glob aborts navigation", async ({ page }) => {
const server = createServer((_, res) => res.end("hi"));
server.listen(0);
const port = (server.address() as any).port;
await page.route("http://*/foo{", route => route.continue());
await page.goto("http://localhost:" + port + "/"); // hangs, then ERR_ABORTED
});
Other patterns that trigger this
| Glob |
Emitted regex |
Error |
"{foo" |
/^(foo$/ |
Unterminated group |
"}foo" |
/^)foo$/ |
Unmatched ')' |
"**/*.png?{" |
/^(.*/)([^/]*)\.png\?($/ |
Unterminated group |
"https://example.com/{a" |
/^https://example\.com/(a$/ |
Unterminated group |
Root cause
packages/isomorphic/urlMatch.ts lines 58–65: case '{' unconditionally emits ( and
case '}' unconditionally emits ) with no balance check. An unmatched brace produces
an invalid regex that throws SyntaxError at request-match time.
Expected behavior
Either validate the glob early and throw a descriptive error (Invalid glob pattern: unbalanced '{'),
or treat unbalanced braces as literals (like most glob libraries do).
Environment
- Playwright version: 1.59.1
- OS: Linux (Ubuntu on WSL2)
- Node.js: v22.11.0
Description
When a glob pattern with unbalanced
{or}is passed topage.route(), the internalglobToRegexPattern()emits an unterminated regex group. When a real HTTP request is made,new RegExp(pattern)throwsSyntaxError: Invalid regular expressioninside the routematcher — silently aborting the request. The page never loads and navigation times out with
net::ERR_ABORTED.Minimal repro
Other patterns that trigger this
"{foo"/^(foo$/"}foo"/^)foo$/"**/*.png?{"/^(.*/)([^/]*)\.png\?($/"https://example.com/{a"/^https://example\.com/(a$/Root cause
packages/isomorphic/urlMatch.tslines 58–65:case '{'unconditionally emits(andcase '}'unconditionally emits)with no balance check. An unmatched brace producesan invalid regex that throws
SyntaxErrorat request-match time.Expected behavior
Either validate the glob early and throw a descriptive error (
Invalid glob pattern: unbalanced '{'),or treat unbalanced braces as literals (like most glob libraries do).
Environment