Skip to content

Commit

Permalink
support for scheme standard according to rfc3986#section-3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
itboy87 committed Jan 1, 2024
1 parent 3369d0e commit d1b4385
Show file tree
Hide file tree
Showing 2 changed files with 15 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 @@ -101,7 +101,7 @@ data class URL private constructor(
defaultPort = port
)

private val schemeRegex = Regex("^([a-zA-Z]+)(?::([a-zA-Z]+))?:")
private val schemeRegex = Regex("^([a-zA-Z0-9+.-]+)(?::([a-zA-Z]+))?:")

operator fun invoke(url: String): URL {
val r = StrReader(url)
Expand Down
14 changes: 14 additions & 0 deletions korge-core/test/korlibs/io/net/URLTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,20 @@ class URLTest {
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
fun testNormalize() {
assertEquals("g", "./g/.".pathInfo.normalize())
Expand Down

0 comments on commit d1b4385

Please sign in to comment.