Skip to content

Commit

Permalink
🔀 Merge pull request #130 from vinceglb/129-javaneturisyntaxexception…
Browse files Browse the repository at this point in the history
…-illegal-character-in-path

🐛 Fix Illegal character in path on Linux
  • Loading branch information
vinceglb authored Oct 4, 2024
2 parents c558051 + c8e87d8 commit 6ed3c5b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
4 changes: 4 additions & 0 deletions filekit-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ kotlin {
implementation(libs.kotlinx.coroutines.core)
}

commonTest.dependencies {
implementation(libs.kotlin.test)
}

androidMain.dependencies {
implementation(libs.androidx.activity.ktx)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.freedesktop.dbus.types.Variant
import java.awt.Window
import java.io.File
import java.net.URI
import java.nio.file.Paths
import java.util.UUID

//https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.FileChooser.html
Expand Down Expand Up @@ -177,7 +178,10 @@ internal class XdgFilePickerPortal : PlatformFilePicker {
val results = params[1] as Map<String, Variant<*>>

if (response.toInt() == 0) {
val uris = (results["uris"]!!.value as List<String>).map { URI(it) }
val uris = (results["uris"]!!.value as List<String>).map { path ->
val filePath = Paths.get(path)
filePath.toUri()
}
onComplete(uris, this)
} else {
onComplete(null, this)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.github.vinceglb.filekit.core.platform.xdg

import java.net.URI
import java.nio.file.Paths
import kotlin.test.Test
import kotlin.test.assertEquals

class URITest {
@Test
fun testSimpleURI() {
val path = "/home/user/file.txt"
val uri = URI(path)
assertEquals(path, uri.path)
}

@Test
fun testURIWithSpaces() {
val path = "/home/user/file with spaces.txt"
val filePath = Paths.get(path)
val uri = filePath.toUri()
assertEquals(path, uri.path)
}

@Test
fun testURIWithSpecialCharacters() {
val path = "/home/user/Ubuntu [24.04].file"
val filePath = Paths.get(path)
val uri = filePath.toUri()
assertEquals(path, uri.path)
}
}
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
agp = "8.6.1"
agp = "8.7.0"
android-activity-ktx = "1.9.2"
android-compose = "1.9.2"
coilCompose = "3.0.0-alpha10"
Expand All @@ -22,6 +22,7 @@ jna = { module = "net.java.dev.jna:jna", version.ref = "jna" }
jna-platform = { module = "net.java.dev.jna:jna-platform", version.ref = "jna" }
observable-viewmodel = { module = "com.rickclephas.kmp:kmp-observableviewmodel-core", version.ref = "observable-viewmodel" }
koin-compose = { module = "io.insert-koin:koin-compose", version.ref = "koinCompose" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
kotlinx-coroutines-swing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "kotlinx-coroutines" }

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Apr 04 20:22:39 CEST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit 6ed3c5b

Please sign in to comment.