-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Globstar **
causes exponential runtime behavior
#237
Comments
Interesting. The way a series of modifiers works is, in a different way, also interesting. This tokenizes as
It seems not too hard to just drop the modifier when we have a full wildcard. Would that be enough? I think you could still make it exponential in such regex engines by writing Honestly I'm not sure of the utility of applying any of the modifiers to |
Dropping the modifier under those conditions is enough to generate a benign Regarding I've also ran both through the unmodified urlpattern-polyfill:
So interestingly, there already is some inconsistency, where |
What is the issue with the URL Pattern Standard?
I've recently come across this bug report in the popular urlpattern-polyfill library. Under "§ 2.2. Converting part lists to regular expressions", a pattern such as
is converted to the regex
/^((?:.*)*)\.google\.com$/u
. This regular expression runs in exponential time under V8, and even breaks on sufficiently long input in SpiderMonkey with the error "InternalError: too much recursion". Of the major JS engines, only WebKit is able to execute it in linear time. The globstar pattern is very common in many globbing languages/libraries, for example minimatch. Software wanting to adopt the standardized URLPattern in exchange for the underspecified space of globbing dialects, will eventually have to deal with end user's code subtly breaking due to this (example).
To avoid this, and under the assumption that there is not much value in emitting
((?:.*)*)
, would it maybe be possible to interpret globstars as unnamed groups, i.e.(.*)
? I suspect that there was likely a reason not to support this pattern, but I haven't been able to find any discussion around the topic of globstars in relation to this spec, so I wanted to at least raise it publicly.Interestingly, while the exponential runtime behavior happens with the polyfill, the native V8 URLPattern implementation does not appear to suffer the same issue.
The text was updated successfully, but these errors were encountered: