Infinite loop with custom list_item_pattern
joserwan opened this issue · comments
Mistune 2.x here.
I'm trying to add the character • (bullet, unicode u2022) as a list item marker :
mistune.BlockParser.LIST_START = re.compile('( {0,3})([\\*\\+\\u2022\\-]|\\d{1,9}[.)])(?:[ \\t]*|[ \\t][^\\n]+)\\n+')
This ends with an infinite loop in the methode _create_list_item_pattern
, since it doesn't match any of the default markdown markers :
# mistune/block_parser.py:320
if marker == '*':
prefix = prefix + r'\*'
elif marker == '+':
prefix = prefix + r'\+'
else:
prefix = prefix + r'-'
I finally made it work with the following else
case :
# mistune/block_parser.py:320
if marker == '*':
prefix = prefix + r'\*'
elif marker == '+':
prefix = prefix + r'\+'
else:
prefix = prefix + rf'{marker}'
Is there any risk to use a variable into the generated regex ? Is there any chance this change to be included in Mistune 2.x ?
Actually this if else is not required:
prefix + re.escape(marker)
is enough
v2.0.5 is released.