Skip to content

Commit 11f6e56

Browse files
authored
fix(android): normalize path before running public directory check (#8)
1 parent 2fdcafb commit 11f6e56

File tree

1 file changed

+8
-4
lines changed
  • packages/capacitor-plugin/android/src/main/java/com/capacitorjs/plugins/filetransfer

1 file changed

+8
-4
lines changed

packages/capacitor-plugin/android/src/main/java/com/capacitorjs/plugins/filetransfer/FileTransferPlugin.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import kotlinx.coroutines.cancel
2525
import kotlinx.coroutines.flow.catch
2626
import kotlinx.coroutines.flow.launchIn
2727
import kotlinx.coroutines.flow.onEach
28+
import androidx.core.net.toUri
2829

2930
@CapacitorPlugin(
3031
name = "FileTransfer",
@@ -323,19 +324,22 @@ class FileTransferPlugin : Plugin() {
323324
* @return Returns true if the file path is in a public directory
324325
*/
325326
private fun isPublicDirectory(filePath: String): Boolean {
327+
// Normalize to path if it is a uri path
328+
val normalizedPath = filePath.toUri().path ?: filePath
329+
326330
// Check if the path is in external storage
327331
val externalStoragePath = Environment.getExternalStorageDirectory().absolutePath
328-
332+
329333
// Get package directory paths
330334
val appPrivatePaths = listOf(
331335
context.filesDir.absolutePath,
332336
context.cacheDir.absolutePath,
333337
context.getExternalFilesDir(null)?.absolutePath,
334338
context.externalCacheDir?.absolutePath
335339
)
336-
340+
337341
// Check if path is in external storage but not in app-specific directories
338-
return filePath.startsWith(externalStoragePath) &&
339-
appPrivatePaths.none { it != null && filePath.startsWith(it) }
342+
return normalizedPath.startsWith(externalStoragePath) &&
343+
appPrivatePaths.none { it != null && normalizedPath.startsWith(it) }
340344
}
341345
}

0 commit comments

Comments
 (0)