Skip to content

Commit

Permalink
fix(core): escape glob characters in drop/dialogs , closes #5234
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Sep 19, 2022
1 parent 1d7171a commit 36e6f04
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changes/escape-pattern.md
@@ -0,0 +1,5 @@
---
"tauri": "patch"
---

Escape glob special characters in files/directories when dropping files or using the open/save dialogs.
15 changes: 11 additions & 4 deletions core/tauri/src/scope/mod.rs
Expand Up @@ -30,17 +30,24 @@ pub(crate) struct Scopes {
impl Scopes {
#[allow(dead_code)]
pub(crate) fn allow_directory(&self, path: &Path, recursive: bool) -> crate::Result<()> {
self.fs.allow_directory(path, recursive)?;
let path = path.to_string_lossy();
let escaped_path = glob::Pattern::escape(&path);

self.fs.allow_directory(&escaped_path, recursive)?;
#[cfg(protocol_asset)]
self.asset_protocol.allow_directory(path, recursive)?;
self
.asset_protocol
.allow_directory(&escaped_path, recursive)?;
Ok(())
}

#[allow(dead_code)]
pub(crate) fn allow_file(&self, path: &Path) -> crate::Result<()> {
self.fs.allow_file(path)?;
let path = path.to_string_lossy();
let escaped_path = glob::Pattern::escape(&path);
self.fs.allow_file(&escaped_path)?;
#[cfg(protocol_asset)]
self.asset_protocol.allow_file(path)?;
self.asset_protocol.allow_file(&escaped_path)?;
Ok(())
}
}

0 comments on commit 36e6f04

Please sign in to comment.