Skip to content

Fix FIND_LINKS_REGEX to match any whitespace after <a#130

Open
danishashko wants to merge 1 commit intoadbar:masterfrom
danishashko:fix/find-links-regex-whitespace
Open

Fix FIND_LINKS_REGEX to match any whitespace after <a#130
danishashko wants to merge 1 commit intoadbar:masterfrom
danishashko:fix/find-links-regex-whitespace

Conversation

@danishashko
Copy link
Copy Markdown

The regex <a [^<>]+?> uses a literal space which misses valid anchor tags that use tabs or multiple spaces between <a and the first attribute.

Changing to <a\s+[^<>]+?> covers any whitespace character, which is more robust and consistent with how HTML is written in the wild.

Quick check:

import re
old = re.compile(r"<a [^<>]+?>", re.I)
new = re.compile(r"<a\s+[^<>]+?>", re.I)
print(bool(old.search('<a\thref="http://example.com">')))  # False
print(bool(new.search('<a\thref="http://example.com">')))  # True

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

Successfully merging this pull request may close these issues.

1 participant