From 96dff22341489459c8cb832fdfd066a588ec23bf Mon Sep 17 00:00:00 2001 From: Nicholas Serra Date: Wed, 20 Jan 2021 17:23:21 -0500 Subject: [PATCH 1/3] Regex DOS fixes --- lib/markdown2.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/markdown2.py b/lib/markdown2.py index bb5260be..f3e41cc1 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -532,7 +532,7 @@ def parse_structured_value(value): return tail - _emacs_oneliner_vars_pat = re.compile(r"-\*-\s*([^\r\n]*?)\s*-\*-", re.UNICODE) + _emacs_oneliner_vars_pat = re.compile(r"-\*-\s*(?:(\S[^\r\n]*?)([\r\n]\s*)?)?-\*-", re.UNICODE) # This regular expression is intended to match blocks like this: # PREFIX Local Variables: SUFFIX # PREFIX mode: Tcl SUFFIX @@ -892,8 +892,8 @@ def _do_numbering(self, text): ''' # First pass to define all the references self.regex_defns = re.compile(r''' - \[\#(\w+)\s* # the counter. Open square plus hash plus a word \1 - ([^@]*)\s* # Some optional characters, that aren't an @. \2 + \[\#(\w+) # the counter. Open square plus hash plus a word \1 + ([^@]*) # Some optional characters, that aren't an @. \2 @(\w+) # the id. Should this be normed? \3 ([^\]]*)\] # The rest of the text up to the terminating ] \4 ''', re.VERBOSE) @@ -908,7 +908,7 @@ def _do_numbering(self, text): if len(match.groups()) != 4: continue counter = match.group(1) - text_before = match.group(2) + text_before = match.group(2).strip() ref_id = match.group(3) text_after = match.group(4) number = counters.get(counter, 1) @@ -1926,7 +1926,7 @@ def _do_code_blocks(self, text): _fenced_code_block_re = re.compile(r''' (?:\n+|\A\n?) - ^```\s*?([\w+-]+)?\s*?\n # opening fence, $1 = optional lang + ^```\s{0,2}([\w+-]+)?\s*?\n # opening fence, $1 = optional lang (.*?) # $2 = code block content ^```[ \t]*\n # closing fence ''', re.M | re.X | re.S) From e1954d3a345fc7a4ccc113bd58f7df81ad63b6ec Mon Sep 17 00:00:00 2001 From: Nicholas Serra Date: Wed, 20 Jan 2021 17:27:21 -0500 Subject: [PATCH 2/3] Pretty comment alignment --- lib/markdown2.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/markdown2.py b/lib/markdown2.py index f3e41cc1..61bb6f69 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -1926,9 +1926,9 @@ def _do_code_blocks(self, text): _fenced_code_block_re = re.compile(r''' (?:\n+|\A\n?) - ^```\s{0,2}([\w+-]+)?\s*?\n # opening fence, $1 = optional lang - (.*?) # $2 = code block content - ^```[ \t]*\n # closing fence + ^```\s{0,2}([\w+-]+)?\s*?\n # opening fence, $1 = optional lang + (.*?) # $2 = code block content + ^```[ \t]*\n # closing fence ''', re.M | re.X | re.S) def _fenced_code_block_sub(self, match): From c4b4ccb3f9da33f29b013d6d765fd223a8277cfe Mon Sep 17 00:00:00 2001 From: Nicholas Serra Date: Wed, 20 Jan 2021 18:28:54 -0500 Subject: [PATCH 3/3] Be forgiving --- lib/markdown2.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/markdown2.py b/lib/markdown2.py index 61bb6f69..61b22006 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -1926,9 +1926,9 @@ def _do_code_blocks(self, text): _fenced_code_block_re = re.compile(r''' (?:\n+|\A\n?) - ^```\s{0,2}([\w+-]+)?\s*?\n # opening fence, $1 = optional lang - (.*?) # $2 = code block content - ^```[ \t]*\n # closing fence + ^```\s{0,99}([\w+-]+)?\s{0,99}\n # opening fence, $1 = optional lang + (.*?) # $2 = code block content + ^```[ \t]*\n # closing fence ''', re.M | re.X | re.S) def _fenced_code_block_sub(self, match):