-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: J. Nick Koston <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
7128872
commit 3273936
Showing
9 changed files
with
130 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Started rejecting ASCII hostnames with invalid characters. For host strings that | ||
look like authority strings, the exception message includes advice on what to do | ||
instead -- by :user:`mjpieters`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
880.bugfix.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ facto | |
glibc | ||
hardcoded | ||
hostnames | ||
macOS | ||
mailto | ||
manylinux | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,6 +120,25 @@ def test_build_with_authority_and_host(): | |
URL.build(authority="host.com", host="example.com") | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("host", "is_authority"), | ||
[ | ||
("user:[email protected]", True), | ||
("[email protected]", True), | ||
("host:com", False), | ||
("not_percent_encoded%Zf", False), | ||
("still_not_percent_encoded%fZ", False), | ||
*(("other_gen_delim_" + c, False) for c in "/?#[]"), | ||
], | ||
) | ||
def test_build_with_invalid_host(host: str, is_authority: bool): | ||
match = r"Host '[^']+' cannot contain '[^']+' \(at position \d+\)" | ||
if is_authority: | ||
match += ", if .* use 'authority' instead of 'host'" | ||
with pytest.raises(ValueError, match=f"{match}$"): | ||
URL.build(host=host) | ||
|
||
|
||
def test_build_with_authority(): | ||
url = URL.build(scheme="http", authority="степан:[email protected]:8000", path="path") | ||
assert ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,6 +171,26 @@ def test_with_host_non_ascii(): | |
assert url2.authority == "оун-упа.укр:123" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("host", "is_authority"), | ||
[ | ||
("user:[email protected]", True), | ||
("[email protected]", True), | ||
("host:com", False), | ||
("not_percent_encoded%Zf", False), | ||
("still_not_percent_encoded%fZ", False), | ||
*(("other_gen_delim_" + c, False) for c in "/?#[]"), | ||
], | ||
) | ||
def test_with_invalid_host(host: str, is_authority: bool): | ||
url = URL("http://example.com:123") | ||
match = r"Host '[^']+' cannot contain '[^']+' \(at position \d+\)" | ||
if is_authority: | ||
match += ", if .* use 'authority' instead of 'host'" | ||
with pytest.raises(ValueError, match=f"{match}$"): | ||
url.with_host(host=host) | ||
|
||
|
||
def test_with_host_percent_encoded(): | ||
url = URL("http://%25cf%2580%cf%80:%25cf%2580%cf%[email protected]:123") | ||
url2 = url.with_host("%cf%80.org") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters