Skip to content

Commit ca7640b

Browse files
committed
Fix some typos in comments, improve some comments, merge some redundant tests
1 parent db0ebfe commit ca7640b

File tree

3 files changed

+14
-22
lines changed

3 files changed

+14
-22
lines changed

email_validator/rfc_constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
# RFC 6531 section 3.3 extends the allowed characters in internationalized
1515
# addresses to also include three specific ranges of UTF8 defined in
16-
# RFC3629 section 4, which appear to be the Unicode code points from
16+
# RFC 3629 section 4, which appear to be the Unicode code points from
1717
# U+0080 to U+10FFFF.
1818
ATEXT_INTL = ATEXT + u"\u0080-\U0010FFFF"
1919
ATEXT_INTL_RE = re.compile('[.' + ATEXT_INTL + ']') # ATEXT_INTL plus dots

email_validator/syntax.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def validate_email_local_part(local: str, allow_smtputf8: bool = True, allow_emp
4545
"smtputf8": False,
4646
}
4747

48-
# Check the length of the local part by couting characters.
48+
# Check the length of the local part by counting characters.
4949
# (RFC 5321 4.5.3.1.1)
5050
# We're checking the number of characters here. If the local part
5151
# is ASCII-only, then that's the same as bytes (octets). If it's
@@ -97,7 +97,7 @@ def validate_email_local_part(local: str, allow_smtputf8: bool = True, allow_emp
9797
# so we'll return the normalized local part in the return value.
9898
local = unicodedata.normalize("NFC", local)
9999

100-
# Check for unsafe characters.
100+
# Check that the local part is a valid, safe, and sensible Unicode string.
101101
# Some of this may be redundant with the range U+0080 to U+10FFFF that is checked
102102
# by DOT_ATOM_TEXT_INTL. Other characters may be permitted by the email specs, but
103103
# they may not be valid, safe, or sensible Unicode strings.

tests/test_syntax.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,16 @@ def test_email_valid_intl_local_part(email_input, output):
256256
"The part after the @-sign contains invalid characters (Codepoint U+2488 not allowed "
257257
"at position 1 in '⒈wouldbeinvalid.com')."),
258258
('@example.com', 'There must be something before the @-sign.'),
259+
('white space@test', 'The email address contains invalid characters before the @-sign: SPACE.'),
260+
('test@white space', 'The part after the @-sign contains invalid characters: SPACE.'),
259261
('\nmy@example.com', 'The email address contains invalid characters before the @-sign: U+000A.'),
260262
('m\ny@example.com', 'The email address contains invalid characters before the @-sign: U+000A.'),
261263
('my\n@example.com', 'The email address contains invalid characters before the @-sign: U+000A.'),
264+
<<<<<<< HEAD
265+
=======
266+
('test@\n', 'The part after the @-sign contains invalid characters: U+000A.'),
267+
('bad"quotes"@example.com', 'The email address contains invalid characters before the @-sign: \'"\'.'),
268+
>>>>>>> 6146614 (fixup)
262269
('11111111112222222222333333333344444444445555555555666666666677777@example.com', 'The email address is too long before the @-sign (1 character too many).'),
263270
('111111111122222222223333333333444444444455555555556666666666777777@example.com', 'The email address is too long before the @-sign (2 characters too many).'),
264271
('me@1111111111222222222233333333334444444444555555555.6666666666777777777788888888889999999999000000000.1111111111222222222233333333334444444444555555555.6666666666777777777788888888889999999999000000000.111111111122222222223333333333444444444455555555556.com', 'The email address is too long (4 characters too many).'),
@@ -318,7 +325,8 @@ def test_email_invalid_reserved_domain(email_input):
318325
],
319326
)
320327
def test_email_unsafe_character(s, expected_error):
321-
# Check for various unsafe characters:
328+
# Check for various unsafe characters that are permitted by the email
329+
# specs but should be disallowed for being unsafe or not sensible Unicode.
322330

323331
with pytest.raises(EmailSyntaxError) as exc_info:
324332
validate_email(s + "@test", test_environment=True)
@@ -329,30 +337,14 @@ def test_email_unsafe_character(s, expected_error):
329337
assert "The email address contains unsafe characters" in str(exc_info.value)
330338

331339

332-
@pytest.mark.parametrize(
333-
('email_input', 'expected_error'),
334-
[
335-
('white space@test', 'The email address contains invalid characters before the @-sign: SPACE.'),
336-
('test@white space', 'The part after the @-sign contains invalid characters: SPACE.'),
337-
('\n@test', 'The email address contains invalid characters before the @-sign: U+000A.'),
338-
('test@\n', 'The part after the @-sign contains invalid characters: U+000A.'),
339-
],
340-
)
341-
def test_email_invalid_character(email_input, expected_error):
342-
# Check for various unsafe test_email_invalid_character_smtputf8:
343-
with pytest.raises(EmailSyntaxError) as exc_info:
344-
validate_email(email_input, test_environment=True)
345-
assert str(exc_info.value) == expected_error
346-
347-
348340
@pytest.mark.parametrize(
349341
('email_input', 'expected_error'),
350342
[
351343
('λambdaツ@test', 'Internationalized characters before the @-sign are not supported: \'λ\', \'\'.'),
352344
],
353345
)
354346
def test_email_invalid_character_smtputf8(email_input, expected_error):
355-
# Check for various unsafe characters:
347+
# Check that internationalized characters are rejected if allow_smtputf8=False.
356348
with pytest.raises(EmailSyntaxError) as exc_info:
357349
validate_email(email_input, allow_smtputf8=False, test_environment=True)
358350
assert str(exc_info.value) == expected_error
@@ -545,7 +537,7 @@ def test_pyisemail_tests(email_input, status):
545537
elif "_ERR_" in status or "_TOOLONG" in status \
546538
or "_CFWS_FWS" in status or "_CFWS_COMMENT" in status \
547539
or "_IPV6" in status or status == "ISEMAIL_RFC5322_DOMAIN":
548-
# Invalid syntax, extranous whitespace, and "(comments)" should be rejected.
540+
# Invalid syntax, extraneous whitespace, and "(comments)" should be rejected.
549541
# The _IPV6_ diagnoses appear to represent syntactically invalid domain literals.
550542
# The ISEMAIL_RFC5322_DOMAIN diagnosis appears to be a syntactically invalid domain.
551543
with pytest.raises(EmailSyntaxError):

0 commit comments

Comments
 (0)