Skip to content

page.route() silently aborts navigation when glob contains unbalanced { or } #40422

@007bsd

Description

@007bsd

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions