Skip to content

Preserve Unicode when serializing relative IRI paths - #206

Open
Dcastroro wants to merge 1 commit into
python-hyper:masterfrom
Dcastroro:fix/preserve-relative-iri-path-text
Open

Dcastroro wants to merge 1 commit into
python-hyper:masterfrom
Dcastroro:fix/preserve-relative-iri-path-text

Conversation

@Dcastroro

Copy link
Copy Markdown

URL.from_text("café/path").to_iri().to_text() currently returns caf%C3%A9/path: _encode_path_parts() drops the maximal=False option for the first schemeless segment. Forward the option so textual IRI output preserves Unicode, while to_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:

  • Regression fails on the unchanged implementation and passes after the fix.
  • URL, DecodedURL and URL doctests: 108 passed. Changed-file Black 21.7b0, Flake8 3.9.2, mypy 0.910 and git diff --check pass.
  • Full suite with seed 237858325326282355359246794251327781884: before 134 passed / 2 failed; after 135 passed / 1 failed. The remaining test_hostnames_ascii_nolead filtering 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.
  • Full mypy reports 16 errors confined to the unchanged Hypothesis strategy/test files; both changed files pass. Other interpreter/platform combinations were not run locally.

Copilot AI balanced review requested due to automatic review settings October 30, 2026 12:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 maximal option 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants