Skip to content

Commit f93bc7c

Browse files
committed
test: write invisible and confusable test characters as escapes
The lookalike tests added with the IDNA mapping check contained literal soft hyphens, zero width characters, a variation selector, a byte order mark and ASCII-confusable letters. They test the right values, but are invisible or indistinguishable from ASCII when reading or reviewing the source. Write them as \u escapes; the tests are unchanged.
1 parent 8a5b260 commit f93bc7c

4 files changed

Lines changed: 19 additions & 17 deletions

File tree

‎tests/test_domain.py‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,20 +173,20 @@ def test_returns_failed_validation_on_domain_beyond_rfc_limits(value: str):
173173
"value",
174174
[
175175
# IDNA 2003 maps these to "example.com"; see `_relies_on_idna_mapping`
176-
"example.com", # fullwidth letters
177-
"example.com",
178-
"example.ⅽom", # small roman numeral one hundred
179-
"Kelvin.com", # Kelvin sign
180-
"ſhop.com", # long s
176+
"example.\uff43\uff4f\uff4d", # fullwidth letters
177+
"\uff45\uff58\uff41\uff4d\uff50\uff4c\uff45.com",
178+
"example.\u217dom", # small roman numeral one hundred
179+
"\u212aelvin.com", # Kelvin sign
180+
"\u017fhop.com", # long s
181181
"example。com", # ideographic full stop
182-
"example.com", # fullwidth full stop
183-
"example。com", # halfwidth ideographic full stop
184-
"exam­ple.com", # soft hyphen
185-
"example.co​m", # zero width space
186-
"exa‍mple.com", # zero width joiner
187-
"exam️ple.com", # variation selector
188-
"examp⁠le.com", # word joiner
189-
"example.com", # zero width no-break space
182+
"example\uff0ecom", # fullwidth full stop
183+
"example\uff61com", # halfwidth ideographic full stop
184+
"exam\u00adple.com", # soft hyphen
185+
"example.co\u200bm", # zero width space
186+
"exa\u200dmple.com", # zero width joiner
187+
"exam\ufe0fple.com", # variation selector
188+
"examp\u2060le.com", # word joiner
189+
"\ufeffexample.com", # zero width no-break space
190190
"exämple.com".replace("ä", "ä"), # not NFC
191191
],
192192
)

‎tests/test_email.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_rejects_newline_after_local_part(local_part: str):
6868
assert isinstance(email(f"{local_part}\n@example.com"), ValidationError)
6969

7070

71-
@pytest.mark.parametrize("domain_part", ["example.com", "exam­ple.com"])
71+
@pytest.mark.parametrize("domain_part", ["example.\uff43\uff4f\uff4d", "exam\u00adple.com"])
7272
def test_returns_failed_validation_on_idna_mapped_lookalike_domain(domain_part: str):
7373
"""Test returns failed validation on email domains that only IDNA 2003 mapping makes valid."""
7474
assert isinstance(email(f"user@{domain_part}"), ValidationError)

‎tests/test_hostname.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,15 @@ def test_rejects_trailing_newline_in_hostnames_and_ports(value: str):
127127
assert isinstance(hostname(value), ValidationError)
128128

129129

130-
@pytest.mark.parametrize("value", ["ſerver", "Kelvin", "ıntranet", "İntranet:8080"])
130+
@pytest.mark.parametrize(
131+
"value", ["\u017ferver", "\u212aelvin", "\u0131ntranet", "\u0130ntranet:8080"]
132+
)
131133
def test_returns_failed_validation_on_non_ascii_simple_hostname(value: str):
132134
"""Test returns failed validation on non-ASCII case equivalents in simple hostnames."""
133135
assert isinstance(hostname(value), ValidationError)
134136

135137

136-
@pytest.mark.parametrize("value", ["example.com", "exam­ple.com:443"])
138+
@pytest.mark.parametrize("value", ["example.\uff43\uff4f\uff4d", "exam\u00adple.com:443"])
137139
def test_returns_failed_validation_on_idna_mapped_lookalike_hostname(value: str):
138140
"""Test returns failed validation on hostnames that only IDNA 2003 mapping makes valid."""
139141
assert isinstance(hostname(value), ValidationError)

‎tests/test_url.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def test_url_accepts_percent_encoded_controls(encoded: str, template: str):
261261

262262
@pytest.mark.parametrize(
263263
"value",
264-
["https://example.com/", "https://exam­ple.com/", "http://ſerver/"],
264+
["https://example.\uff43\uff4f\uff4d/", "https://exam\u00adple.com/", "http://\u017ferver/"],
265265
)
266266
def test_returns_failed_validation_on_idna_mapped_lookalike_url(value: str):
267267
"""Test returns failed validation on url hosts that only IDNA 2003 mapping makes valid."""

0 commit comments

Comments
 (0)