-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀 Merge pull request #134 from vinceglb/fix-path-linux-3
🐛 Fix URISyntaxException: Illegal character in path 3
- Loading branch information
Showing
2 changed files
with
44 additions
and
21 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
32 changes: 16 additions & 16 deletions
32
filekit-core/src/jvmTest/kotlin/io/github/vinceglb/filekit/core/platform/xdg/URITest.kt
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 |
---|---|---|
@@ -1,34 +1,34 @@ | ||
package io.github.vinceglb.filekit.core.platform.xdg | ||
|
||
import java.net.URI | ||
import java.net.URLEncoder | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class URITest { | ||
private fun String.URI(): URI = URLEncoder | ||
.encode(this, "UTF-8") | ||
.replace("+", "%20") | ||
.let { URI(it) } | ||
|
||
@Test | ||
fun testSimpleURI() { | ||
val path = "/home/user/file.txt" | ||
val uri = path.URI() | ||
assertEquals(path, uri.path) | ||
val path = "image:///home/user/file.txt" | ||
val uri = path.toURI() | ||
assertEquals("/home/user/file.txt", uri.path) | ||
} | ||
|
||
@Test | ||
fun testURIWithSpaces() { | ||
val path = "/home/user/file with spaces.txt" | ||
val uri = path.URI() | ||
assertEquals(path, uri.path) | ||
val path = "file:///home/user/file with spaces.txt" | ||
val uri = path.toURI() | ||
assertEquals("/home/user/file with spaces.txt", uri.path) | ||
} | ||
|
||
@Test | ||
fun testURIWithSpecialCharacters() { | ||
val path = "/home/user/Ubuntu [24.04].file" | ||
val uri = path.URI() | ||
assertEquals(path, uri.path) | ||
val path = "file:///home/user/Ubuntu [24.04].file" | ||
val uri = path.toURI() | ||
assertEquals("/home/user/Ubuntu [24.04].file", uri.path) | ||
} | ||
|
||
@Test | ||
fun testURIWithoutScheme() { | ||
val path = "/home/user/file.txt" | ||
val uri = path.toURI() | ||
assertEquals("/home/user/file.txt", uri.path) | ||
} | ||
} |