Skip to content

refactor: consolidate host/authority/path serialization#47

Merged
OmarAlJarrah merged 1 commit into
mainfrom
refactor/consolidate-serialization
Jul 8, 2026
Merged

refactor: consolidate host/authority/path serialization#47
OmarAlJarrah merged 1 commit into
mainfrom
refactor/consolidate-serialization

Conversation

@OmarAlJarrah

Copy link
Copy Markdown
Member

What

Host / authority / URL-path serialization was reimplemented in several places instead of delegating to the canonical renderers.

  • parser/Resolver held a byte-for-byte copy of host/HostSerialization's serializeHost (the host when, the zone-id suffix, the "%25" constant) — a latent drift bug: change host serialization and the resolution path silently diverges.
  • Url.encodedPath and Url.authority re-implemented Serializer's URL-path and authority serialization, including the non-obvious leading-/. path guard.
  • An internal Host.serialize() extension duplicated the public Host.asText() (identical body).

Change

  • Resolver now calls serializeHost; its copy is deleted.
  • Promoted Serializer's path/authority helpers to internal top-level serializeUrlPath / serializeAuthority; Url delegates to them and Serializer keeps using them.
  • Removed the Host.serialize() synonym and routed callers to asText(). This drops one tautological Ipv6Test that only asserted serialize() == asText(); asText() remains covered by the host-validation / ipv4 / ipv6 suites and the Kover floor still holds.

Left duplicated on purpose

  • Uri.reconstructAuthority — its nullable-userInfo empty→null distinction can't be expressed by the string-only shared helper.
  • Resolver's authority assembly — the logic is identical to the shared helper, but importing serialize into parser would form a package cycle with the existing serialize→parser edge (UriNormalizer→Resolver.removeDotSegments). Four trivial lines aren't worth a cycle.

Safety

Pure refactor — no behavior change, public API unchanged (apiCheck passes with no apiDump). Verified on the JVM gate + koverVerify + a Kotlin/Native macosArm64 compile. Net −53 lines.


Stacked on #46.

@OmarAlJarrah OmarAlJarrah force-pushed the refactor/centralize-grammar-char-classes branch from 5f30ed1 to 4037494 Compare July 8, 2026 10:08
@OmarAlJarrah OmarAlJarrah changed the base branch from refactor/centralize-grammar-char-classes to main July 8, 2026 10:23
Serialization logic was reimplemented in several places instead of delegating
to the canonical renderers:

  - parser/Resolver held a byte-for-byte copy of host/HostSerialization's
    serializeHost (the host `when`, the zone-id suffix, the "%25" constant) —
    a latent drift bug in the resolution path's re-serialization. Deleted; it
    now calls serializeHost.
  - Url.encodedPath and Url.authority re-implemented Serializer's URL-path and
    authority serialization, including the non-obvious leading-"/." path guard.
    Promoted Serializer's helpers to internal top-level functions
    (serializeUrlPath, serializeAuthority) and delegated Url to them; Serializer
    still uses them itself.
  - Removed the redundant internal Host.serialize() extension — a synonym for
    the public Host.asText() with an identical body — and routed its callers to
    asText(). This drops one tautological Ipv6 test that only asserted the two
    synonyms agree; asText() stays covered by the host validation / ipv4 / ipv6
    suites and the coverage floor still holds.

Two duplications are left in place on purpose. Uri.reconstructAuthority keeps
its own assembly: its nullable-userInfo empty->null distinction can't be
expressed by the string-only shared helper. Resolver's authority assembly is
also left duplicated — consolidating it would add a parser->serialize import
and form a package cycle with the existing serialize->parser edge, which four
trivial lines don't justify.

Pure refactor: no behavior change, public API unchanged.
@OmarAlJarrah OmarAlJarrah force-pushed the refactor/consolidate-serialization branch from 37d0b91 to 7e0814c Compare July 8, 2026 10:27
@OmarAlJarrah OmarAlJarrah merged commit c83284b into main Jul 8, 2026
9 checks passed
@OmarAlJarrah OmarAlJarrah deleted the refactor/consolidate-serialization branch July 8, 2026 10:28
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.

1 participant