trentm / python-markdown2

markdown2: A fast and complete implementation of Markdown in Python
Other
2.66k stars 433 forks source link

Fix link patterns extra matching against internal hashes #501

Closed Crozzers closed 1 year ago

Crozzers commented 1 year ago

This PR fixes #287 by preventing any link pattern regular expressions from matching against internal hashes.

It does this by checking the overlap between any link pattern match and the positions of the hashes in the text. If a link pattern matches against text inside the start-end positions of an internal hash, it is ignored.

nicholasserra commented 1 year ago

What's the side effect here, does a block of text we'd normally be hashing get skipped? Haven't dove into this yet, apologies.

Crozzers commented 1 year ago

In theory, no. A match is only rejected when it starts or ends within an internal hash, so unless the user is exploiting the internal hashing mechanism and intentionally matching the hashes, it shouldn't break anything.

Just in case, I could add some arguments for the link patterns extra so that users can turn this behaviour off

nicholasserra commented 1 year ago

Guess i'm just confused how people are reporting collisions in the first place. I honestly haven't spent much time looking at it yet, so I should dive in before I keep asking questions lol

Thank you

nicholasserra commented 1 year ago

Awesome