-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fixed a few cases of exponential backtracking #2268
Conversation
Nice work! Regarding Textile, would it help to constrain the modifier regexp more? Actually, maybe it's even simpler to just ban |
Ok. I solved it by using a special pattern for parentheses. |
I'm currently writing a library to construct NFA from JS RegExp, so plugged it into Prism's pattern test to check for exponential backtracking and fixed (almost) all offending patterns. Please note that my test was not great. It only tested for one kind of exponential backtracking and it couldn't handle assertions and lookarounds at all, so there might very well be other patterns that still have exponential backtracking.
Now for the complex part: Textile.
The
modifierRegex
looks like this:\([^|)]+\)|\[[^\]]+\]|\{[^}]+\}
with the important parting being the\([^|)]+\)
. Many pattern then use the pattern like this:(?:<MOD>|[<>=()])+
to get modifiers and some other characters.The problem is that these other characters include
(
and)
, so for a string of the form/(?:\(=\)){100}/
there are 2^100 ways to match it.The problem here is that I can't just remove the
()
from the set of other characters because unholy creations likep((. some text
are valid.So, how do we solve this?
(I refactored textile a little anyway.)