Skip to content

Commit

Permalink
Resolve issue with catastrophic backtracking regex (#436)
Browse files Browse the repository at this point in the history
Catastrophic backtracking in the `BREAK_THEMATIC_R` regex causes parsing to hang on non-matching input with repeating asterisks like this:
```
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
SOME TEXT
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
```
or even just:
```
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
```
This minor regex change resolves that issue without changing the matched pattern or capture group.
  • Loading branch information
Prestaul committed Feb 2, 2023
1 parent 31ff137 commit cb1dee5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion index.tsx
Expand Up @@ -259,7 +259,7 @@ const BLOCK_END_R = /\n{2,}$/
const BLOCKQUOTE_R = /^( *>[^\n]+(\n[^\n]+)*\n*)+\n{2,}/
const BLOCKQUOTE_TRIM_LEFT_MULTILINE_R = /^ *> ?/gm
const BREAK_LINE_R = /^ {2,}\n/
const BREAK_THEMATIC_R = /^(?:( *[-*_]) *){3,}(?:\n *)+\n/
const BREAK_THEMATIC_R = /^(?:( *[-*_])){3,} *(?:\n *)+\n/
const CODE_BLOCK_FENCED_R =
/^\s*(`{3,}|~{3,}) *(\S+)?([^\n]*?)?\n([\s\S]+?)\s*\1 *(?:\n *)*\n?/
const CODE_BLOCK_R = /^(?: {4}[^\n]+\n*)+(?:\n *)+\n?/
Expand Down

0 comments on commit cb1dee5

Please sign in to comment.