Skip to content

Commit 4e1fd81

Browse files
committed
Reject text paths in decoded replace
1 parent 978f2e6 commit 4e1fd81

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/hyperlink/_url.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,10 @@ def replace(
22652265
automatically encoded instead of an error being raised.
22662266
"""
22672267
if path is not _UNSET:
2268+
if isinstance(path, Text):
2269+
raise TypeError(
2270+
"expected iterable of text for path, not: %r" % (path,)
2271+
)
22682272
path = tuple(_encode_reserved(p) for p in path)
22692273
if query is not _UNSET:
22702274
query = cast(

src/hyperlink/test/test_url.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,18 @@ def test_technicallyTextIsIterableBut(self):
10231023
"expected iterable of text for path, not: {0}".format(repr("foo")),
10241024
)
10251025

1026+
decoded_url = URL.from_text(
1027+
"https://example.com/api/v1/webui"
1028+
).get_decoded_url()
1029+
with self.assertRaises(TypeError) as raised:
1030+
decoded_url.replace(path="support/woo")
1031+
self.assertEqual(
1032+
str(raised.exception),
1033+
"expected iterable of text for path, not: {0}".format(
1034+
repr("support/woo")
1035+
),
1036+
)
1037+
10261038
def test_netloc(self):
10271039
# type: () -> None
10281040
url = URL(scheme="https")

0 commit comments

Comments
 (0)