Skip to content

feat: add Uri/Url redact() and isDirectory()/hasTrailingSlash()#138

Merged
OmarAlJarrah merged 2 commits into
mainfrom
a9-redact-isdirectory
Jul 19, 2026
Merged

feat: add Uri/Url redact() and isDirectory()/hasTrailingSlash()#138
OmarAlJarrah merged 2 commits into
mainfrom
a9-redact-isdirectory

Conversation

@OmarAlJarrah

Copy link
Copy Markdown
Member

Summary

  • SPEC.md documents redact() (CONF-120) and directory-path accessors (CONF-85, PATH-3) as MUST-level requirements, but neither existed on Uri or Url — the closest thing was withoutFragment(), which only handles the fragment.
  • Add redact() to both types: it removes userinfo (username/password on Url), query, and fragment while leaving scheme, host, port, and path untouched, following the same newBuilder()-rebuild pattern withoutFragment() already uses. On an opaque-path URL like mailto:user@example.com, the user@ text is part of the opaque path rather than real userinfo, so it's correctly left alone.
  • Add isDirectory() and hasTrailingSlash() (exact aliases, matching the two names SPEC.md calls out) to both types: they report whether the path's serialization ends in / — a trailing empty segment — covering the root path, an explicit trailing slash, and an opaque path uniformly.

Test plan

  • ./gradlew :kuri:jvmTest — new Kotlin (UriDxTest, UrlDxTest) and Java interop (PublicApiDxJavaTest) cases for redact(), isDirectory(), and hasTrailingSlash() on both types, including root path, trailing slash, no-trailing-slash, opaque path, a relative Uri reference, and a value with no userinfo/query/fragment already (no-op check)
  • ./gradlew :kuri:ktlintCheck
  • ./gradlew :kuri:detekt
  • ./gradlew :kuri:apiCheck (jvm + android + native klib, run on macOS so the Apple targets are included)
  • ./gradlew :kuri:jsNodeTest (commonMain changed)
  • ./gradlew :kuri:macosArm64Test (native target compiles and passes)
  • ./gradlew apiDump on macOS, regenerated api/jvm/kuri.api, api/android/kuri.api, and api/kuri.klib.api (verified the Apple targets are present in the klib dump)

Closes #111

SPEC.md documented these as MUST-level requirements (CONF-120,
CONF-85, PATH-3) but neither was ever implemented, so callers had no
way to strip credentials/query/fragment before logging a URL, or to
detect a directory-style path, without falling back to manual string
inspection.

redact() removes userinfo (or username/password for Url), query, and
fragment while leaving scheme, host, port, and path untouched, mirroring
the existing withoutFragment() builder-rebuild pattern. isDirectory()
and hasTrailingSlash() are aliases that report whether the path's
serialization ends in "/" (a trailing empty segment), covering the root
path, a genuine trailing slash, and opaque paths uniformly.

Closes #111
ComponentPath.Opaque's trailing-slash check only had a test asserting
the false case (a mailto: address with no trailing slash). Add a case
for an opaque path that does end in a slash so both outcomes of that
branch are exercised.
@OmarAlJarrah
OmarAlJarrah merged commit 326b5a0 into main Jul 19, 2026
11 of 12 checks passed
@OmarAlJarrah
OmarAlJarrah deleted the a9-redact-isdirectory branch July 19, 2026 17:08
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.

kuri: SPEC.md documents public methods redact() and isDirectory/hasTrailingSlash that do not exist

1 participant