fix: model Uri userinfo username/password as nullable#142
Open
OmarAlJarrah wants to merge 1 commit into
Open
Conversation
…sence ParsedComponents stored username and password as non-null strings defaulting to "", so an absent userinfo/password and a present-but-empty one collapsed to the same value before serialization ever ran. That broke the Uri PRESERVE profile's own equality contract: "http://@h/" re-serialized to "http://h/" (losing the "@") and "http://u:@h/" re-serialized to "http://u@h/" (losing the trailing ":"), so URIs that are syntactically different compared equal. Model username/password as String? through the parse pipeline instead: null means the component wasn't present at all, "" means it was present but empty. The Uri profile's serializer, equals/hashCode (both derived from uriString), userInfo accessor, structured resolver, and normalizer now all preserve that distinction. The Url (WHATWG) profile has no such distinction in its own spec, so its parser, serializer, and public username/password accessors keep treating "" as absent, unchanged in behavior. Closes #104
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
ParsedComponentsstoredusername/passwordas non-null strings defaulting to"", which collapsed "absent" and "present-but-empty" into the same value before serialization ever ran.UriPRESERVE profile's own documented equality contract:http://@h/re-serialized tohttp://h/(losing the@), andhttp://u:@h/re-serialized tohttp://u@h/(losing the trailing:), so two syntactically distinct URIs compared equal.username/passwordare now modeled asString?through the parse pipeline:nullmeans the component wasn't present at all,""means it was present but empty.Uri's serializer (and thereforeequals/hashCode, both derived fromuriString),userInfoaccessor, structured resolver, and normalizer all now preserve that distinction, andUri.Builderround-trips it vianewBuilder().build().Url(WHATWG) profile has no absent-vs-present-empty userinfo distinction in its own spec, so its parser, serializer, and publicusername/passwordaccessors are unchanged in behavior (they still treat""as absent).Test plan
./gradlew :kuri:jvmTest— new regression tests added toUriTest,UriParserTest,UriBuilderTest,UriBuilderUserInfoTest, and an existingResolverTestcase updated for the corrected behavior./gradlew :kuri:ktlintCheck./gradlew :kuri:detekt./gradlew :kuri:jvmApiCheckand./gradlew :kuri:klibApiCheck— no public API shape change (ParsedComponentsisinternal), confirmed with no diff;androidApiCheckcould not run in this environment (no Android SDK configured), which is a pre-existing environment gap unrelated to this change./gradlew :kuri:jsNodeTest(commonMain touched)./gradlew :kuri:macosArm64Test(native compile sanity check)./gradlew :kuri:koverVerifyJvmCloses #104