-
-
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.
Normalize URL string ports per RFC 3986 section 3.2.3
Previously, `yarl.URL` string representation would sometimes render ports for well-known URI schemes. However, section 3.2.3 of RFC 3986 explicitly instructs us to omit it [[1]]. This patch does exactly that. PR #1033 [1]: https://datatracker.ietf.org/doc/html/rfc3986.html#section-3.2.3 Co-authored-by: Sam Bull <[email protected]> Co-authored-by: Sviatoslav Sydorenko <[email protected]>
- Loading branch information
1 parent
56a1d6b
commit d5c5ab3
Showing
4 changed files
with
76 additions
and
5 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,6 @@ | ||
The default protocol ports of well-known URI schemes are now taken into account | ||
during the normalization of the URL string representation in accordance with | ||
:rfc:`3986#section-3.2.3`. | ||
|
||
Specified ports are removed from the :class:`str` representation of a :class:`~yarl.URL` | ||
if the port matches the scheme's default port -- by :user:`commonism`. |
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 |
---|---|---|
|
@@ -219,6 +219,12 @@ def test_authority_full_nonasci() -> None: | |
assert url.authority == "степан:пароль@слава.укр:8080" | ||
|
||
|
||
def test_authority_unknown_scheme() -> None: | ||
v = "scheme://user:[email protected]:43/path/to?a=1&b=2" | ||
url = URL(v) | ||
assert str(url) == v | ||
|
||
|
||
def test_lowercase(): | ||
url = URL("http://gitHUB.com") | ||
assert url.raw_host == "github.com" | ||
|
@@ -1332,6 +1338,7 @@ def test_is_default_port_for_absolute_url_without_port(): | |
def test_is_default_port_for_absolute_url_with_default_port(): | ||
url = URL("http://example.com:80") | ||
assert url.is_default_port() | ||
assert str(url) == "http://example.com" | ||
|
||
|
||
def test_is_default_port_for_absolute_url_with_nondefault_port(): | ||
|
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 does blocking I/O an is not async safe