Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop reencoding URL when calling with_port() #623

Merged
merged 3 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/623.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Changed call in `with_port()` to stop reencoding parts of the URL that were already encoded.
elciok marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions tests/test_url_update_netloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ def test_with_port_keeps_query_and_fragment():
assert str(url.with_port(8888)) == "http://example.com:8888/?a=1#frag"


def test_with_port_percent_encoded():
url = URL("http://user%name:pass%[email protected]/")
assert str(url.with_port(808)) == "http://user%25name:pass%[email protected]:808/"


def test_with_port_for_relative_url():
with pytest.raises(ValueError):
URL("path/to").with_port(1234)
Expand Down
4 changes: 1 addition & 3 deletions yarl/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,9 +883,7 @@ def with_port(self, port):
val = self._val
return URL(
self._val._replace(
netloc=self._make_netloc(
val.username, val.password, val.hostname, port, encode=True
)
netloc=self._make_netloc(val.username, val.password, val.hostname, port)
),
encoded=True,
)
Expand Down