malformed HTML causes a regex backtracking lockup
See original GitHub issueTry execute following code in node.js v8.7.0 repl:
const a =`<g>
<g>
<path fill="#ffffff"/>
</g>
<path fill="#ffffff"/>`
var HTML_BLOCK_ELEMENT_R = /^ *<([^ >/]+) ?([^>]*)\/{0}>(?=[\s\S]*<\/\1>)((?:[\s\S]*?(?:<\1[^>]*>[\s\S]*?<\/\1>)*[\s\S]*?)*?)<\/\1>\n*/
HTML_BLOCK_ELEMENT_R.exec(a)
node.js will hang at last command
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Catastrophic Backtracking - Runaway Regular Expressions
The reason is that all the tokens are mutually exclusive. None of them can match any characters matched by any of the others....
Read more >Catastrophic backtracking - The Modern JavaScript Tutorial
The typical symptom – a regular expression works fine sometimes, but for certain strings it “hangs”, consuming 100% of CPU. In such case...
Read more >JavaScript regex exec takes too long to execute - Stack Overflow
Just noticed: While the [ ]+ solves the backtracking issue, it means that all captures have to end with a space. – ojrac....
Read more >Catastrophic backtracking in regex allows Denial of Service
When waitress receives a header that contains invalid characters it will cause the regular expression engine to catastrophically backtrack ...
Read more >Stack Overflow Outage Postmortem - Hacker News
"Today, regular expressions have also become a shining example of how ignoring good theory leads to bad programs. The regular expression ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Please read https://www.regular-expressions.info/catastrophic.html, we’ve run into a catastrofic backtrack.
Released as
6.5.0