Refactor RegExps to avoid the possibility of polynomial backtracking (fixes #657).

This commit is contained in:
David Anson 2024-10-05 18:07:45 -07:00
parent 9b1840a5a4
commit e0219411c6
8 changed files with 14 additions and 16 deletions

View file

@ -24,7 +24,7 @@ module.exports.nextLinesRe = nextLinesRe;
// Regular expression for matching common front matter (YAML and TOML)
module.exports.frontMatterRe =
/((^---\s*$[\s\S]+?^---\s*)|(^\+\+\+\s*$[\s\S]+?^(\+\+\+|\.\.\.)\s*)|(^\{\s*$[\s\S]+?^\}\s*))(\r\n|\r|\n|$)/m;
/((^---[^\S\r\n\u2028\u2029]*$[\s\S]+?^---\s*)|(^\+\+\+[^\S\r\n\u2028\u2029]*$[\s\S]+?^(\+\+\+|\.\.\.)\s*)|(^\{[^\S\r\n\u2028\u2029]*$[\s\S]+?^\}\s*))(\r\n|\r|\n|$)/m;
// Regular expression for matching the start of inline disable/enable comments
const inlineCommentStartRe =