Skip to content

Infinite loop with custom list_item_pattern #331

@joserwan

Description

@joserwan

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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions