Require a local-part to be a valid email address in AUTOMAIL_RE. by nzlosh · Pull Request #1165 · Python-Markdown/markdown (original) (raw)
Valid email addresses require a local-part before the @
followed by domain. This PR updates the AUTOMAIL_RE
to use the +
quantifier to require 1 or more characters in the local-part instead of the *
quantifier which allows 0 characters.
The current regex allows the invalid addresses in the form <@domain>
. My particular use case is formatting messages in Slack, where mentioned users take the form <@Uxxxxx>
. markdown is incorrectly processing the mention string form as an email address. I still want markdown's automail feature for processing email addressing in the text.
>>> AUTOMAIL_RE = r'<([^<> !]*@[^@<> ]*)>'
>>> print(re.match(AUTOMAIL_RE, "<@localhost>"))
<re.Match object; span=(0, 12), match='<@localhost>'>
>>> print(re.match(AUTOMAIL_RE, "<bob@localhost>"))
<re.Match object; span=(0, 15), match='<bob@localhost>'>
>>> AUTOMAIL_RE = r'<([^<> !]+@[^@<> ]*)>'
>>> print(re.match(AUTOMAIL_RE, "<@localhost>"))
None
>>> print(re.match(AUTOMAIL_RE, "<bob@localhost>"))
<re.Match object; span=(0, 15), match='<bob@localhost>'>