From 57f6ef40a5a53eed11c8f1660f04419934539176 Mon Sep 17 00:00:00 2001 From: "david.castro" Date: Fri, 30 Oct 2026 13:37:19 +0100 Subject: [PATCH] Preserve Unicode in relative IRI path serialization --- src/hyperlink/_url.py | 4 +++- src/hyperlink/test/test_url.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/hyperlink/_url.py b/src/hyperlink/_url.py index 8797b5cc..2937c090 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 37c91726..35f0ee8c 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)"