Skip to content

Commit

Permalink
URL schemes always lowercase fixes issue #2092 (#2102)
Browse files Browse the repository at this point in the history
  • Loading branch information
itboy87 committed Dec 31, 2023
1 parent e617e70 commit e7f2a98
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion korge-core/src/korlibs/io/net/URL.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ data class URL private constructor(
fragment: String?,
opaque: Boolean = false,
port: Int = DEFAULT_PORT
): URL = URL(opaque, scheme, userInfo, host, path, query, fragment, port)
): URL = URL(opaque, scheme?.lowercase(), userInfo, host, path, query, fragment, port)

private val schemeRegex = Regex("\\w+:")

Expand Down
17 changes: 17 additions & 0 deletions korge-core/test/korlibs/io/net/URLTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,23 @@ class URLTest {
for (url in URLS) assertEquals(url.isOpaque, URL(url.url).isOpaque, url.url)
}

@Test
fun testURL(){
val url = URL("HTTPS://Google.com:442/test?q=1")
assertEquals("https", url.scheme) // always lowercase issue #2092
assertEquals("Google.com", url.host)
assertEquals(442, url.port)
assertEquals("/test", url.path)
assertEquals("/test?q=1", url.pathWithQuery)
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)
assertEquals("https", url2.scheme)
assertEquals(443, url2.port)
assertEquals("https://Google.com", url2.fullUrl)
}

@Test
fun testNormalize() {
assertEquals("g", "./g/.".pathInfo.normalize())
Expand Down

0 comments on commit e7f2a98

Please sign in to comment.