Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency with null and empty fragment in URI #338

Open
OptimumCode opened this issue Jun 10, 2024 · 5 comments
Open

Inconsistency with null and empty fragment in URI #338

OptimumCode opened this issue Jun 10, 2024 · 5 comments

Comments

@OptimumCode
Copy link

Hi,

I have noticed that the URI with an empty (not null) fragment parsed from the string is not equal to a URI with an empty fragment created with Uri.Builder (the URI created from the builder does not have # in the end if an empty fragment was set).

I would think that if a fragment is empty the # should be added at the end of the URI string representation.

If you agree, I will create a PR with changes and tests.

Here you can find a small example to reproduce the case:

import com.eygraber.uri.Uri
import io.kotest.assertions.assertSoftly
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe

class UriTest : FunSpec() {
  init {
    test("uri from string with empty fragment is not the same as build uri with empty fragment") {
      val fromStrWithEmptyFragment = Uri.parse("https://test.com#")
      val fromStrWithNullFragment = Uri.parse("https://test.com")
      val builtWithEmptyFragment =
        Uri.Builder()
          .scheme("https")
          .authority("test.com")
          .fragment("")
          .build()

      val builtWithNullFragment =
        Uri.Builder()
          .scheme("https")
          .authority("test.com")
          .fragment(null)
          .build()

      assertSoftly {
        fromStrWithEmptyFragment shouldBe builtWithEmptyFragment
        fromStrWithNullFragment shouldBe builtWithNullFragment
      }
    }
  }
}

Thank you!

@eygraber
Copy link
Owner

I try to follow Android's Uri so if the behavior you're seeing matches that, I would leave it.

Otherwise please feel free to file a PR.

@OptimumCode
Copy link
Author

I will check URI implementation in Android, thank you

@OptimumCode
Copy link
Author

I have checked the Android sources and it looks like the behavior in Android's URI is the same.
I will report this to the Android team - if they agree that the behaviour should be changed I will create a PR here.
Does this sound good to you, @eygraber?

@OptimumCode
Copy link
Author

@eygraber
Copy link
Owner

Absolutely, thank you!

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

No branches or pull requests

2 participants