Skip to content
Draft
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
4 changes: 4 additions & 0 deletions src/hyperlink/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -2265,6 +2265,10 @@ def replace(
automatically encoded instead of an error being raised.
"""
if path is not _UNSET:
if isinstance(path, Text):
raise TypeError(
"expected iterable of text for path, not: %r" % (path,)
)
path = tuple(_encode_reserved(p) for p in path)
if query is not _UNSET:
query = cast(
Expand Down
12 changes: 12 additions & 0 deletions src/hyperlink/test/test_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,18 @@ def test_technicallyTextIsIterableBut(self):
"expected iterable of text for path, not: {0}".format(repr("foo")),
)

decoded_url = URL.from_text(
"https://example.com/api/v1/webui"
).get_decoded_url()
with self.assertRaises(TypeError) as raised:
decoded_url.replace(path="support/woo")
self.assertEqual(
str(raised.exception),
"expected iterable of text for path, not: {0}".format(
repr("support/woo")
),
)

def test_netloc(self):
# type: () -> None
url = URL(scheme="https")
Expand Down