diff --git a/src/hyperlink/_url.py b/src/hyperlink/_url.py index 8797b5c..2937c09 100644 --- a/src/hyperlink/_url.py +++ b/src/hyperlink/_url.py @@ -333,7 +333,9 @@ def _encode_path_parts( for part in text_parts ] else: - encoded_parts = [_encode_schemeless_path_part(text_parts[0])] + encoded_parts = [ + _encode_schemeless_path_part(text_parts[0], maximal=maximal) + ] encoded_parts.extend( [ _encode_path_part(part, maximal=maximal) if part else part diff --git a/src/hyperlink/test/test_url.py b/src/hyperlink/test/test_url.py index 37c9172..35f0ee8 100644 --- a/src/hyperlink/test/test_url.py +++ b/src/hyperlink/test/test_url.py @@ -1344,6 +1344,16 @@ def test_schemeless_path(self): u6 = URL.from_text(u5.to_text()).to_uri() assert u5 == u6 # colons stay decoded bc they're not in the first seg + def test_schemeless_iri_path(self): + # type: () -> None + """Relative IRI paths preserve Unicode while escaping delimiters.""" + url = URL(path=("café:menu", "next")) + iri_text = "café%3Amenu/next" + uri_text = "caf%C3%A9%3Amenu/next" + assert url.to_text() == iri_text + assert url.to_uri().to_text() == uri_text + assert URL.from_text(uri_text).to_iri().to_text() == iri_text + def test_emoji_domain(self): # type: () -> None "See issue #7, affecting only narrow builds (2.6-3.3)"