From e03dca60e7c9219e24095e8da46f775fc9137e76 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Fri, 9 Oct 2026 13:25:05 -0300 Subject: [PATCH] fix(fs): accept absolute paths in the iOS security-scope commands (#3628) In plugins/fs/src/commands.rs, start/stop_accessing_security_scoped_resource only handled SafeFilePath::Url, so a plain path was a silent no-op although the JS docs say "path or file:// URL" (and Fs::stop_accessing_security_scoped_resource accepts paths). Absolute paths are now converted to file:// URLs first; relative paths keep being ignored. iOS-only code: formatted but not compiled here (the iOS tauri build script fails in this environment). --- .changes/fix-fs-ios-security-scope-paths.md | 6 ++++++ plugins/fs/src/commands.rs | 14 ++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 .changes/fix-fs-ios-security-scope-paths.md diff --git a/.changes/fix-fs-ios-security-scope-paths.md b/.changes/fix-fs-ios-security-scope-paths.md new file mode 100644 index 000000000..e1366c800 --- /dev/null +++ b/.changes/fix-fs-ios-security-scope-paths.md @@ -0,0 +1,6 @@ +--- +fs: patch +fs-js: patch +--- + +`startAccessingSecurityScopedResource` and `stopAccessingSecurityScopedResource` now accept absolute paths on iOS, as documented, instead of silently doing nothing unless given a `file://` URL. diff --git a/plugins/fs/src/commands.rs b/plugins/fs/src/commands.rs index 1a022a893..6e136dd57 100644 --- a/plugins/fs/src/commands.rs +++ b/plugins/fs/src/commands.rs @@ -1311,10 +1311,13 @@ pub fn start_accessing_security_scoped_resource( #[cfg(target_os = "ios")] { use crate::FilePath; - // Convert SafeFilePath to FilePath + // Convert SafeFilePath to FilePath, handling absolute paths as `file://` URLs let file_path: FilePath = match &path { SafeFilePath::Url(url) => FilePath::Url(url.clone()), - SafeFilePath::Path(safe_path) => FilePath::Path(safe_path.as_ref().to_owned()), + SafeFilePath::Path(safe_path) => match url::Url::from_file_path(safe_path.as_ref()) { + Ok(url) => FilePath::Url(url), + Err(()) => FilePath::Path(safe_path.as_ref().to_owned()), + }, }; // Only handle file URLs @@ -1382,10 +1385,13 @@ pub fn stop_accessing_security_scoped_resource( #[cfg(target_os = "ios")] { use crate::{FilePath, FsExt}; - // Convert SafeFilePath to FilePath + // Convert SafeFilePath to FilePath, handling absolute paths as `file://` URLs let file_path: FilePath = match &path { SafeFilePath::Url(url) => FilePath::Url(url.clone()), - SafeFilePath::Path(safe_path) => FilePath::Path(safe_path.as_ref().to_owned()), + SafeFilePath::Path(safe_path) => match url::Url::from_file_path(safe_path.as_ref()) { + Ok(url) => FilePath::Url(url), + Err(()) => FilePath::Path(safe_path.as_ref().to_owned()), + }, }; // Only handle file URLs