question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

malformed HTML causes a regex backtracking lockup

See original GitHub issue

Try 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:closed
  • Created 6 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
hugmanriquecommented, Feb 24, 2018

Please read https://www.regular-expressions.info/catastrophic.html, we’ve run into a catastrofic backtrack.

0reactions
probablyupcommented, Mar 7, 2018

Released as 6.5.0

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found