From 704260bb3c2bc54c149f2fe508bff09535b083ad Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Wed, 15 May 2024 18:45:11 +0300 Subject: [PATCH] fix(macos/dialog): avoid setting empty `default_path` (#9784) closes #7566 ref: https://github.com/tauri-apps/tauri/issues/4065 ref: https://github.com/tauri-apps/tauri/pull/4028 ref: https://github.com/tauri-apps/tauri/issues/9762 --- .changes/macos-dialog-crash-default-path-empty.md | 5 +++++ core/tauri/src/endpoints/dialog.rs | 4 ++++ 2 files changed, 9 insertions(+) create mode 100644 .changes/macos-dialog-crash-default-path-empty.md diff --git a/.changes/macos-dialog-crash-default-path-empty.md b/.changes/macos-dialog-crash-default-path-empty.md new file mode 100644 index 000000000..2ae3f076c --- /dev/null +++ b/.changes/macos-dialog-crash-default-path-empty.md @@ -0,0 +1,5 @@ +--- +"tauri": "patch:bug" +--- + +Fix dialog crash on macOS when the `default_path` value is empty. diff --git a/core/tauri/src/endpoints/dialog.rs b/core/tauri/src/endpoints/dialog.rs index f9f051477..0cb7cccb3 100644 --- a/core/tauri/src/endpoints/dialog.rs +++ b/core/tauri/src/endpoints/dialog.rs @@ -301,6 +301,10 @@ fn set_default_path( mut dialog_builder: FileDialogBuilder, default_path: PathBuf, ) -> FileDialogBuilder { + if default_path.as_os_str().is_empty() { + return dialog_builder; + } + // we need to adjust the separator on Windows: https://github.com/tauri-apps/tauri/issues/8074 let default_path: PathBuf = default_path.components().collect(); if default_path.is_file() || !default_path.exists() {