@@ -128,7 +128,7 @@ def validate_email_local_part(local, allow_smtputf8=True, allow_empty_local=Fals
128128 raise EmailSyntaxError ("The email address is too long before the @-sign." )
129129
130130 # Check the local part against the regular expression for the older ASCII requirements.
131- m = re .match (DOT_ATOM_TEXT + "$ " , local )
131+ m = re .match (DOT_ATOM_TEXT + "\\ Z " , local )
132132 if m :
133133 # Return the local part unchanged and flag that SMTPUTF8 is not needed.
134134 return {
@@ -138,7 +138,7 @@ def validate_email_local_part(local, allow_smtputf8=True, allow_empty_local=Fals
138138
139139 else :
140140 # The local part failed the ASCII check. Now try the extended internationalized requirements.
141- m = re .match (DOT_ATOM_TEXT_UTF8 + "$ " , local )
141+ m = re .match (DOT_ATOM_TEXT_UTF8 + "\\ Z " , local )
142142 if not m :
143143 # It's not a valid internationalized address either. Report which characters were not valid.
144144 bad_chars = ', ' .join (sorted (set (
@@ -226,15 +226,15 @@ def validate_email_domain_part(domain):
226226
227227 # Check the regular expression. This is probably entirely redundant
228228 # with idna.decode, which also checks this format.
229- m = re .match (DOT_ATOM_TEXT + "$ " , domain )
229+ m = re .match (DOT_ATOM_TEXT + "\\ Z " , domain )
230230 if not m :
231231 raise EmailSyntaxError ("The email address contains invalid characters after the @-sign." )
232232
233233 # All publicly deliverable addresses have domain named with at least
234234 # one period. We also know that all TLDs end with a letter.
235235 if "." not in domain :
236236 raise EmailSyntaxError ("The domain name %s is not valid. It should have a period." % domain_i18n )
237- if not re .search (r"[A-Za-z]$ " , domain ):
237+ if not re .search (r"[A-Za-z]\Z " , domain ):
238238 raise EmailSyntaxError (
239239 "The domain name %s is not valid. It is not within a valid top-level domain." % domain_i18n
240240 )
0 commit comments