-
Notifications
You must be signed in to change notification settings - Fork 122
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
Add subScheme
Support and Align with RFC 3986 Section 3.1
for Scheme Extraction (Fixes #2101)
#2110
Merged
soywiz
merged 5 commits into
korlibs:main
from
itboy87:fix/2101-add-subprotocol-support-in-url
Jan 3, 2024
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3369d0e
add subScheme support in URL.kt
itboy87 d1b4385
support for scheme standard according to rfc3986#section-3.1
itboy87 0a95008
Merge branch 'main' into fix/2101-add-subprotocol-support-in-url
itboy87 ed6f635
URL.invoke overload function for backward compatibility.
itboy87 4bafcd7
Deprecate URL.invoke with parameters and introduce replacement using …
itboy87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,10 +111,65 @@ class URLTest { | |
assertEquals("q=1", url.query) | ||
assertEquals("https://Google.com:442/test?q=1", url.fullUrl) | ||
|
||
val url2 = URL(scheme = "HTTPs", userInfo = null, host = "Google.com", path = "", query = null, fragment = null) | ||
val url2 = URL(scheme = "HTTPs", subScheme = null, userInfo = null, host = "Google.com", path = "", query = null, fragment = null) | ||
assertEquals("https", url2.scheme) | ||
assertEquals(443, url2.port) | ||
assertEquals("https://Google.com", url2.fullUrl) | ||
|
||
val url3 = URL("https://username:[email protected]:8443/path/to/resource?q=1") | ||
assertEquals("https", url3.scheme) | ||
assertNull(url3.subScheme) | ||
assertEquals("username:password", url3.userInfo) | ||
assertEquals("username", url3.user) | ||
assertEquals("password", url3.password) | ||
assertEquals("example.com", url3.host) | ||
assertEquals(8443, url3.port) | ||
assertEquals("/path/to/resource", url3.path) | ||
assertEquals("/path/to/resource?q=1", url3.pathWithQuery) | ||
assertEquals("q=1", url3.query) | ||
assertEquals("https://username:[email protected]:8443/path/to/resource?q=1", url3.fullUrl) | ||
} | ||
|
||
@Test | ||
fun testSubSchemeUrls(){ | ||
// <scheme>:<subScheme>://<host>:<port>/<path>?<query_parameters>#<fragment> | ||
val url = URL("jdbc:mysql://localhost:3306/database?useSSL=false") | ||
assertEquals("jdbc", url.scheme) // always lowercase issue #2092 | ||
assertEquals("mysql", url.subScheme) | ||
assertEquals("localhost", url.host) | ||
assertEquals(3306, url.port) | ||
assertEquals("/database", url.path) | ||
assertEquals("/database?useSSL=false", url.pathWithQuery) | ||
assertEquals("useSSL=false", url.query) | ||
assertEquals("jdbc:mysql://localhost:3306/database?useSSL=false", url.fullUrl) | ||
|
||
val url2 = URL(scheme = "jdbc", subScheme = "mysql", userInfo = null, host = "localhost", path = "/database", query = null, fragment = null, port = 3306) | ||
assertEquals("jdbc:mysql://localhost:3306/database", url2.fullUrl) | ||
|
||
|
||
val url3 = URL("jdbc:mysql://localhost:3306/database?useSSL=false") | ||
assertEquals("jdbc", url3.scheme) // always lowercase issue #2092 | ||
assertEquals("mysql", url3.subScheme) | ||
assertEquals("localhost", url3.host) | ||
assertEquals(3306, url3.port) | ||
assertEquals("/database", url3.path) | ||
assertEquals("/database?useSSL=false", url3.pathWithQuery) | ||
assertEquals("useSSL=false", url3.query) | ||
assertEquals("jdbc:mysql://localhost:3306/database?useSSL=false", url3.fullUrl) | ||
} | ||
|
||
@Test | ||
fun testUrlScheme() { | ||
// test scheme standard (rfc3986#section-3.1): ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) | ||
val url = URL("custom+scheme123://example.com/path/to/resource") | ||
assertEquals("custom+scheme123", url.scheme) | ||
assertEquals("example.com", url.host) | ||
assertEquals("custom+scheme123://example.com/path/to/resource", url.fullUrl) | ||
|
||
val url2 = URL("alpha-numeric+scheme.123://example.com/path/to/resource") | ||
assertEquals("alpha-numeric+scheme.123", url2.scheme) | ||
assertEquals("example.com", url2.host) | ||
assertEquals("alpha-numeric+scheme.123://example.com/path/to/resource", url2.fullUrl) | ||
} | ||
|
||
@Test | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we should either create a new overload keeping the old (for compatibility), or placing the subScheme at the end to avoid people not using named arguments to have broken code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively maybe we could just support subschemes by using
scheme = "jdbc:mysql"
and validating it somewhere else and providingsubScheme
andmainScheme
or something like that as read-only properties?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should create an overload function and keep the
subScheme
variable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we create a
fun fromComponents
, keep theinvoke
as it is and mark it as deprecated? The main problem is that since we have several strings in a row and named arguments are not mandatory, this might be a compatibility problemThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per my suggestion,
URL(..)
offers a much better and developer-friendly syntax compared toURL.fromComponents
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, we should at least deprecate the other signature:
But let me insist:
The problem with the invoke is probably disambiguation in some circumstances.
Also, let's consider this example:
I would say that forcing to provide nulls for all the arguments is also not a good experience. It would be better to provide all the values as null by default, and since we have a typical
URL(fullUrl: String)
signature, that might be a problem.I would say it could be better to have:
No disambiguation required.
Also you can keep the current invoke, without adding the extra
subScheme
to the end nulled by default, so current code still works like this even if used without named arguments:with the Deprecated, it gives people visibility to the new function. It allows providing all the arguments by default so not having to provide every argument not used as null, as there is no signature conflict with URL(String).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, that sounds better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made changes. Could you please take a look?