From 61bae6634dbc5505bdf924e2f472473a1814bccc Mon Sep 17 00:00:00 2001 From: Elcio Nakashima Date: Sat, 9 Oct 2021 20:41:33 -0300 Subject: [PATCH 1/3] Stop reencoding URL when calling with_port() --- tests/test_url_update_netloc.py | 5 +++++ yarl/_url.py | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test_url_update_netloc.py b/tests/test_url_update_netloc.py index 1c9ba5c0..0dfc4303 100644 --- a/tests/test_url_update_netloc.py +++ b/tests/test_url_update_netloc.py @@ -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%word@example.com/") + assert str(url.with_port(808)) == "http://user%25name:pass%25word@example.com:808/" + + def test_with_port_for_relative_url(): with pytest.raises(ValueError): URL("path/to").with_port(1234) diff --git a/yarl/_url.py b/yarl/_url.py index e5c1e2ce..bb33fce3 100644 --- a/yarl/_url.py +++ b/yarl/_url.py @@ -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, ) From bc18ea80efd0bc7baf769dc2b48fb664894bfc81 Mon Sep 17 00:00:00 2001 From: Elcio Nakashima Date: Sun, 10 Oct 2021 20:20:30 -0300 Subject: [PATCH 2/3] Added change note --- CHANGES/623.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 CHANGES/623.bugfix.rst diff --git a/CHANGES/623.bugfix.rst b/CHANGES/623.bugfix.rst new file mode 100644 index 00000000..a7983006 --- /dev/null +++ b/CHANGES/623.bugfix.rst @@ -0,0 +1 @@ +Changed call in `with_port()` to stop reencoding parts of the URL that were already encoded. From 32cb9c192a82fcffa45e92e406820ea2d5fbcd24 Mon Sep 17 00:00:00 2001 From: elciok Date: Sun, 10 Oct 2021 20:52:18 -0300 Subject: [PATCH 3/3] Fixing CHANGES/623.bugfix.rst code formatting. Co-authored-by: Sviatoslav Sydorenko --- CHANGES/623.bugfix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES/623.bugfix.rst b/CHANGES/623.bugfix.rst index a7983006..fb2d39d6 100644 --- a/CHANGES/623.bugfix.rst +++ b/CHANGES/623.bugfix.rst @@ -1 +1 @@ -Changed call in `with_port()` to stop reencoding parts of the URL that were already encoded. +Changed call in ``with_port()`` to stop reencoding parts of the URL that were already encoded.