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

fix URL.resolve and PathInfo.normalize #2090

Merged
merged 6 commits into from Dec 29, 2023
Merged

fix URL.resolve and PathInfo.normalize #2090

merged 6 commits into from Dec 29, 2023

Conversation

itboy87
Copy link
Contributor

@itboy87 itboy87 commented Dec 28, 2023

Changes in URL.resolve

  • Added new test cases in URLTest.testResolve.
  • Removed old query on the copy of the path.
  • Added protocol for a relative URL.
    • assertEquals("https://example2.com/one", URL.resolve("https://example.com/", "//example2.com/one"))
  • Now returns the base URL if the access URL is empty.
    • assertEquals("https://example.com/one", URL.resolve("https://example.com/one", ""))
  • Introduced a new extension function String.normalizeUrl.
    • Avoids normalizing query parameters or URL fragments.
    • Keeps end slashes after normalization.

Changes in PathInfo.normalize

  • Added new test cases in URLTest.testNormalize.
  • Added a parameter for removeEndSlash.
    • This parameter is introduced to match the standard of the web, but in filesystem paths, it's not required, and the default value is true.
    • assertEquals("g", "g/".pathInfo.normalize())
    • assertEquals("g/", "g/".pathInfo.normalize(removeEndSlash = false))

@itboy87
Copy link
Contributor Author

itboy87 commented Dec 28, 2023

Additionally, as per RFC3986 Secion-3.1 , URL schemes should be case-insensitive, producing only lowercase scheme names for consistency. Should I apply this change in this pull request as well?

@itboy87
Copy link
Contributor Author

itboy87 commented Dec 29, 2023

@soywiz I have one more scenario to handle: if the base URL is empty or not absolute, how should it be resolved? I think we should return the access URL if it's absolute; otherwise, return an empty string or null.
In java.net.URL("") or java.net.URL("test"), a java.net.MalformedURLException exception is thrown.

@soywiz soywiz merged commit 1ffa0dc into korlibs:main Dec 29, 2023
9 checks passed
@soywiz
Copy link
Member

soywiz commented Dec 29, 2023

Thanks @itboy87! I have merged it now as it cover and fixes already some scenarios.

Additionally, as per RFC3986 Secion-3.1 , URL schemes should be case-insensitive, producing only lowercase scheme names for consistency. Should I apply this change in this pull request as well?

Makes sense. Feel free to make a separate PR for that.

@soywiz I have one more scenario to handle: if the base URL is empty or not absolute, how should it be resolved? I think we should return the access URL if it's absolute; otherwise, return an empty string or null.
In java.net.URL("") or java.net.URL("test"), a java.net.MalformedURLException exception is thrown.

I would have URL.resolveOrNull returning null for invalid scenarios, and then make resolve throw the exception; that would be consistent with the Kotlin API. What would you think?

In this case too, let's make those changes in a separate PR.

@itboy87
Copy link
Contributor Author

itboy87 commented Dec 29, 2023

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.

None yet

2 participants