urlpattern icon indicating copy to clipboard operation
urlpattern copied to clipboard

Matching `(` and `)` in a regexp matcher requires escaping

Open lucacasonato opened this issue 1 year ago • 4 comments

Fails, even though it's valid:

const pattern = new URLPattern({ pathname: '/([()])' });
Uncaught TypeError: tokenizer error: invalid regex: nested groups must start with ? (at char 1)

OK:

const pattern = new URLPattern({ pathname: '/([\\(\\)])' });

This is because while tokenizing the pattern, we think the second ( is a nested group rather than just a char in a regexp character class.

Fixing this will make the tokenizer more complicated. Is it worth it?

lucacasonato avatar Jul 10 '23 20:07 lucacasonato