-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
subScheme
Support and Align with RFC 3986 Section 3.1
for Sch…
- Loading branch information
Showing
2 changed files
with
115 additions
and
16 deletions.
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,66 @@ 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.fromComponents(scheme = "HTTPs", host = "Google.com") | ||
assertEquals("https", url2.scheme) | ||
assertEquals(443, url2.port) | ||
assertNull(url2.subScheme) | ||
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.fromComponents(scheme = "jdbc", subScheme = "mysql", host = "localhost", path = "/database", 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 | ||
|