Skip to content

Commit 96dff22

Browse files
committed
Regex DOS fixes
1 parent 330d34c commit 96dff22

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/markdown2.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ def parse_structured_value(value):
532532

533533
return tail
534534

535-
_emacs_oneliner_vars_pat = re.compile(r"-\*-\s*([^\r\n]*?)\s*-\*-", re.UNICODE)
535+
_emacs_oneliner_vars_pat = re.compile(r"-\*-\s*(?:(\S[^\r\n]*?)([\r\n]\s*)?)?-\*-", re.UNICODE)
536536
# This regular expression is intended to match blocks like this:
537537
# PREFIX Local Variables: SUFFIX
538538
# PREFIX mode: Tcl SUFFIX
@@ -892,8 +892,8 @@ def _do_numbering(self, text):
892892
'''
893893
# First pass to define all the references
894894
self.regex_defns = re.compile(r'''
895-
\[\#(\w+)\s* # the counter. Open square plus hash plus a word \1
896-
([^@]*)\s* # Some optional characters, that aren't an @. \2
895+
\[\#(\w+) # the counter. Open square plus hash plus a word \1
896+
([^@]*) # Some optional characters, that aren't an @. \2
897897
@(\w+) # the id. Should this be normed? \3
898898
([^\]]*)\] # The rest of the text up to the terminating ] \4
899899
''', re.VERBOSE)
@@ -908,7 +908,7 @@ def _do_numbering(self, text):
908908
if len(match.groups()) != 4:
909909
continue
910910
counter = match.group(1)
911-
text_before = match.group(2)
911+
text_before = match.group(2).strip()
912912
ref_id = match.group(3)
913913
text_after = match.group(4)
914914
number = counters.get(counter, 1)
@@ -1926,7 +1926,7 @@ def _do_code_blocks(self, text):
19261926

19271927
_fenced_code_block_re = re.compile(r'''
19281928
(?:\n+|\A\n?)
1929-
^```\s*?([\w+-]+)?\s*?\n # opening fence, $1 = optional lang
1929+
^```\s{0,2}([\w+-]+)?\s*?\n # opening fence, $1 = optional lang
19301930
(.*?) # $2 = code block content
19311931
^```[ \t]*\n # closing fence
19321932
''', re.M | re.X | re.S)

0 commit comments

Comments
 (0)