You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve exception messages related to the dot-atom rule and also invalid and unsafe characters
* Check for invalid and (now) unsafe characters in domain names before going to IDNA parsing so we can be more sure we don't generate unsafe strings in error messages. It's also clearer. But these were probably invalid anyway per IDNA rules.
* Check for bad characters in local parts before using the dot-atom regex because the regex can fail because of invalid dot usage and the error message wouldn't indicate that.
* Check for invalid dot usage in the local part explicitly to improve error messages. Add tests.
* Use a safe and intelligible (no Python escape codes) representation of invalid characters in error messages.
raiseEmailSyntaxError("The email address contains invalid characters before the @-sign: "+", ".join(sorted(bad_chars)) +".")
68
+
69
+
# Check for dot errors imposted by the dot-atom rule.
70
+
check_dot_atom(local, 'An email address cannot start with a {}.', 'An email address cannot have a {} immediately before the @-sign.', is_hostname=False)
71
+
44
72
# Check the local part against the regular expression for the older ASCII requirements.
raiseEmailSyntaxError("An email address cannot have two letters followed by two dashes immediately after the @-sign or after a period, except Punycode.")
154
198
155
199
ifDOT_ATOM_TEXT_HOSTNAME.match(domain):
200
+
# This is a valid non-internationalized domain.
156
201
ascii_domain=domain
157
202
else:
158
203
# If international characters are present in the domain name, convert
'The part after the @-sign contains invalid characters (Codepoint U+000A at position 4 of '
230
-
'\'com\\n\' not allowed).'),
229
+
'The part after the @-sign contains invalid characters: U+000A.'),
231
230
('my@example\n.com',
232
-
'The part after the @-sign contains invalid characters (Codepoint U+000A at position 8 of '
233
-
'\'example\\n\' not allowed).'),
234
-
('[email protected]', 'The email address contains invalid characters before the @-sign: FULL STOP.'),
235
-
('[email protected]', 'The email address contains invalid characters before the @-sign: FULL STOP.'),
236
-
('[email protected]', 'The email address contains invalid characters before the @-sign: FULL STOP.'),
231
+
'The part after the @-sign contains invalid characters: U+000A.'),
232
+
('me@x!', 'The part after the @-sign contains invalid characters: \'!\'.'),
233
+
('me@x ', 'The part after the @-sign contains invalid characters: SPACE.'),
234
+
('[email protected]', 'An email address cannot start with a period.'),
235
+
('[email protected]', 'An email address cannot have two periods in a row.'),
236
+
('[email protected]', 'An email address cannot have a period immediately before the @-sign.'),
237
237
('me@⒈wouldbeinvalid.com',
238
238
"The part after the @-sign contains invalid characters (Codepoint U+2488 not allowed "
239
239
"at position 1 in '⒈wouldbeinvalid.com')."),
240
240
('@example.com', 'There must be something before the @-sign.'),
241
-
('\n[email protected]', 'The email address contains invalid characters before the @-sign: \'\\n\'.'),
242
-
('m\n[email protected]', 'The email address contains invalid characters before the @-sign: \'\\n\'.'),
243
-
('my\n@example.com', 'The email address contains invalid characters before the @-sign: \'\\n\'.'),
241
+
('\n[email protected]', 'The email address contains invalid characters before the @-sign: U+000A.'),
242
+
('m\n[email protected]', 'The email address contains invalid characters before the @-sign: U+000A.'),
243
+
('my\n@example.com', 'The email address contains invalid characters before the @-sign: U+000A.'),
244
244
('11111111112222222222333333333344444444445555555555666666666677777@example.com', 'The email address is too long before the @-sign (1 character too many).'),
245
245
('111111111122222222223333333333444444444455555555556666666666777777@example.com', 'The email address is too long before the @-sign (2 characters too many).'),
246
246
('me@1111111111222222222233333333334444444444555555555.6666666666777777777788888888889999999999000000000.1111111111222222222233333333334444444444555555555.6666666666777777777788888888889999999999000000000.111111111122222222223333333333444444444455555555556.com', 'The email address is too long (4 characters too many).'),
('my.λong.address@1111111111222222222233333333334444444444555555555.6666666666777777777788888888889999999999000000000.1111111111222222222233333333334444444444555555555.6666666666777777777788888888889999999999000000000.1111111111222222222233333333334444.info', 'The email address is too long (at least 1 character too many).'),
254
254
('me@bad-tld-1', 'The part after the @-sign is not valid. It should have a period.'),
255
255
('[email protected]', 'The part after the @-sign is not valid. It is not within a valid top-level domain.'),
256
-
('me@x!', 'The part after the @-sign contains invalid characters (Codepoint U+0021 at position 2 of \'x!\' not allowed).'),
257
256
('[email protected]', 'The part after the @-sign is not valid IDNA (Invalid A-label).'),
258
257
('[email protected]', 'An email address cannot have two letters followed by two dashes immediately after the @-sign or after a period, except Punycode.'),
259
258
('me@yy--0.tld', 'An email address cannot have two letters followed by two dashes immediately after the @-sign or after a period, except Punycode.'),
0 commit comments