Skip to content

Commit cfa74eb

Browse files
authored
feat(core): validate dialog default_path (it must exist) (#1599)
1 parent aa7e273 commit cfa74eb

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Validate dialog option `defaultPath` - it must exists.

core/tauri/src/endpoints/dialog.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ fn set_default_path(
144144
pub fn open(options: OpenDialogOptions) -> crate::Result<InvokeResponse> {
145145
let mut dialog_builder = FileDialogBuilder::new();
146146
if let Some(default_path) = options.default_path {
147+
if !default_path.exists() {
148+
return Err(crate::Error::DialogDefaultPathNotExists(default_path));
149+
}
147150
dialog_builder = set_default_path(dialog_builder, default_path);
148151
}
149152
for filter in options.filters {
@@ -165,6 +168,9 @@ pub fn open(options: OpenDialogOptions) -> crate::Result<InvokeResponse> {
165168
pub fn save(options: SaveDialogOptions) -> crate::Result<InvokeResponse> {
166169
let mut dialog_builder = FileDialogBuilder::new();
167170
if let Some(default_path) = options.default_path {
171+
if !default_path.exists() {
172+
return Err(crate::Error::DialogDefaultPathNotExists(default_path));
173+
}
168174
dialog_builder = set_default_path(dialog_builder, default_path);
169175
}
170176
for filter in options.filters {

core/tauri/src/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5+
use std::path::PathBuf;
6+
57
/// Runtime errors that can happen inside a Tauri application.
68
#[derive(Debug, thiserror::Error)]
79
pub enum Error {
@@ -60,6 +62,9 @@ pub enum Error {
6062
/// Error initializing plugin.
6163
#[error("failed to initialize plugin `{0}`: {1}")]
6264
PluginInitialization(String, String),
65+
/// `default_path` provided to dialog API doesn't exist.
66+
#[error("failed to setup dialog: provided default path `{0}` doesn't exist")]
67+
DialogDefaultPathNotExists(PathBuf),
6368
}
6469

6570
impl From<serde_json::Error> for Error {

0 commit comments

Comments
 (0)