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

Keep ipv6 brackets after updating port/user/password #452

Merged
merged 2 commits into from
Jul 18, 2020
Merged
Show file tree
Hide file tree
Changes from all 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/451.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Keep ipv6 brackets after updating port/user/password.
15 changes: 15 additions & 0 deletions tests/test_url_update_netloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def test_with_user_None():
assert str(url.with_user(None)) == "http://example.com"


def test_with_user_ipv6():
url = URL("http://john:pass@[::1]:8080/")
assert str(url.with_user(None)) == "http://[::1]:8080/"


def test_with_user_None_when_password_present():
url = URL("http://john:[email protected]")
assert str(url.with_user(None)) == "http://example.com"
Expand All @@ -65,6 +70,11 @@ def test_with_password():
assert str(url.with_password("pass")) == "http://john:[email protected]"


def test_with_password_ipv6():
url = URL("http://john:pass@[::1]:8080/")
assert str(url.with_password(None)) == "http://john@[::1]:8080/"


def test_with_password_non_ascii():
url = URL("http://[email protected]")
url2 = url.with_password("пароль")
Expand Down Expand Up @@ -149,6 +159,11 @@ def test_with_port():
assert str(url.with_port(8888)) == "http://example.com:8888"


def test_with_port_ipv6():
url = URL("http://[::1]:8080/")
assert str(url.with_port(80)) == "http://[::1]:80/"


def test_with_port_keeps_query_and_fragment():
url = URL("http://example.com/?a=1#frag")
assert str(url.with_port(8888)) == "http://example.com:8888/?a=1#frag"
Expand Down
6 changes: 3 additions & 3 deletions yarl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ def with_user(self, user):
return URL(
self._val._replace(
netloc=self._make_netloc(
user, password, val.hostname, val.port, encode=False
user, password, val.hostname, val.port, encode=True
)
),
encoded=True,
Expand All @@ -788,7 +788,7 @@ def with_password(self, password):
return URL(
self._val._replace(
netloc=self._make_netloc(
val.username, password, val.hostname, val.port, encode=False
val.username, password, val.hostname, val.port, encode=True
)
),
encoded=True,
Expand Down Expand Up @@ -836,7 +836,7 @@ def with_port(self, port):
return URL(
self._val._replace(
netloc=self._make_netloc(
val.username, val.password, val.hostname, port, encode=False
val.username, val.password, val.hostname, port, encode=True
)
),
encoded=True,
Expand Down