Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite loop with custom list_item_pattern #331

Closed
joserwan opened this issue Jan 10, 2023 · 2 comments
Closed

Infinite loop with custom list_item_pattern #331

joserwan opened this issue Jan 10, 2023 · 2 comments

Comments

@joserwan
Copy link

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 ?

@lepture
Copy link
Owner

lepture commented Jan 14, 2023

Actually this if else is not required:

prefix + re.escape(marker)

is enough

lepture added a commit that referenced this issue Feb 7, 2023
@lepture
Copy link
Owner

lepture commented Feb 7, 2023

v2.0.5 is released.

@lepture lepture closed this as completed Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants