Repository navigation
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The single-line forwarding of the maximal flag is a minimal, correct fix with an accompanying regression test and no outstanding objective issues.
No open issues 🎉
What changed in this PR
This PR fixes a bug in hyperlink's IRI serialization where relative (schemeless) paths lost their Unicode characters. Previously _encode_path_parts() always encoded the first schemeless segment with the default maximal=True, so textual IRI output percent-escaped Unicode (e.g. café/path → caf%C3%A9/path). The fix forwards the caller's maximal flag to _encode_schemeless_path_part(), so to_text() (maximal=False) preserves Unicode while still escaping syntactically required delimiters, and to_uri() (maximal=True) continues to emit UTF-8 percent escapes.
Changes:
- Forward the
maximaloption to_encode_schemeless_path_part()for the first schemeless path segment. - Add a regression test asserting IRI text preservation, URI percent-encoding, and URI→IRI round-tripping, including a first-segment colon that must stay escaped.
| File | Description |
|---|---|
| src/hyperlink/_url.py | Passes maximal=maximal into _encode_schemeless_path_part() so IRI text output preserves Unicode in the first relative segment. |
| src/hyperlink/test/test_url.py | Adds test_schemeless_iri_path covering text, URI, and URI-to-IRI conversion with a first-segment colon. |
Review effort: Balanced
URL.from_text("café/path").to_iri().to_text()currently returnscaf%C3%A9/path:_encode_path_parts()drops themaximal=Falseoption for the first schemeless segment. Forward the option so textual IRI output preserves Unicode, whileto_uri()still emits UTF-8 percent escapes and a colon in the first relative segment remains escaped.Adds one regression test with three assertions for text, URI, and URI-to-IRI conversion, including a first-segment colon.
Validation on Windows CPython 3.9.25 with the repository-pinned pytest 5.2.4, Hypothesis 5.8.6 and idna 2.9:
git diff --checkpass.test_hostnames_ascii_noleadfiltering health check also fails on the unchanged implementation and is already tracked by Tests are failing due to hypothesis filtering #186 / Avoid uppercase ASCII labels in hostname strategies #205. No health checks were suppressed.