Closed transiient closed 4 years ago
I just tested this in the Firefox dev console and it even happens there. Woah. Looks like this is a much bigger than issue than I originally thought. That means both SpiderMonkey and V8 have this bug.
You may find this illuminating: https://javascript.info/regexp-catastrophic-backtracking
@devsnek thanks for that article - I guess that's the issue! Only saw your response after I'd filed bug reports in both the Mozilla and Chromium trackers... whoops. Still valid in both though.
I'm closing this as it's not a Node.js issue. Note that it's a longstanding issue and not considered a bug by the JS engines as such (and they have a point - it's a bug in the regular expression, the engine just does what it's told.)
What steps will reproduce the bug?
> node
)string
variable -let
orconst
, doesn't matter. Use backticks as it's a multi-line stringconsole.log(string.match(/\]\(*(.*?)*\)/gi) || []);
How often does it reproduce? Is there a required condition?
Every time you run that sequence of commands with that particular string. I don't know why.
What is the expected behavior?
Output of matched expressions in the string, as shown on Regexr with the exact same string and RegEx expression.
What do you see instead?
Additional information
I was documenting this issue here originally, as I first suspected an issue in Next.js: https://github.com/vercel/next.js/issues/14611 After many hours of debugging, I figured out the issue lies in Node itself.