feat: add Uri/Url redact() and isDirectory()/hasTrailingSlash()#138
Merged
Conversation
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
added a commit
that referenced
this pull request
Jul 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
redact()(CONF-120) and directory-path accessors (CONF-85, PATH-3) as MUST-level requirements, but neither existed onUriorUrl— the closest thing waswithoutFragment(), which only handles the fragment.redact()to both types: it removes userinfo (username/password onUrl), query, and fragment while leaving scheme, host, port, and path untouched, following the samenewBuilder()-rebuild patternwithoutFragment()already uses. On an opaque-path URL likemailto:user@example.com, theuser@text is part of the opaque path rather than real userinfo, so it's correctly left alone.isDirectory()andhasTrailingSlash()(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 forredact(),isDirectory(), andhasTrailingSlash()on both types, including root path, trailing slash, no-trailing-slash, opaque path, a relativeUrireference, 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 apiDumpon macOS, regeneratedapi/jvm/kuri.api,api/android/kuri.api, andapi/kuri.klib.api(verified the Apple targets are present in the klib dump)Closes #111