From f67a4a6bfec8ba21ae75f58c6fc74f12a07d4abf Mon Sep 17 00:00:00 2001 From: WofWca Date: Fri, 14 Mar 2025 07:29:55 +0400 Subject: [PATCH] fix(core): `AssetResolver.get()`: don't skip first char (#12971) That is, it would try to get `sers/john` if you called `AssetResolver.get("users/john")`. This commit fixes the bug by only skipping the first character only if it _is_ a slash (/). Why it is important: `tauri::WebviewUrl::App()` docs state that it's OK to specify the path as `users/john` to get `tauri://localhost/users/john` in the end. So if an application developer is using `AssetResolver.get()` together with `WebviewUrl::App()`, they will would get inconsistent behavior: for the same path, the latter would work, while the former would fail. In fact, we encountered this bug in our code, [here](https://github.com/deltachat/deltachat-desktop/blob/c860b0f4c659cdb0659ba946ecdd7f0381792946/packages/target-tauri/src-tauri/src/help_window.rs#L34-L43). --- .changes/fix-get-asset-no-leading-slash.md | 6 ++++++ crates/tauri/src/manager/mod.rs | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .changes/fix-get-asset-no-leading-slash.md diff --git a/.changes/fix-get-asset-no-leading-slash.md b/.changes/fix-get-asset-no-leading-slash.md new file mode 100644 index 000000000..90257c524 --- /dev/null +++ b/.changes/fix-get-asset-no-leading-slash.md @@ -0,0 +1,6 @@ +--- +'tauri': 'patch:bug' +--- + +Fix `tauri::AssetResolver::get` and `tauri::AssetResolver::get_for_scheme` +skipping the first character of the `path` even if it's not a slash (/). diff --git a/crates/tauri/src/manager/mod.rs b/crates/tauri/src/manager/mod.rs index 882b141ca..98f549527 100644 --- a/crates/tauri/src/manager/mod.rs +++ b/crates/tauri/src/manager/mod.rs @@ -397,8 +397,8 @@ impl AppManager { // if the url is `tauri://localhost`, we should load `index.html` "index.html".to_string() } else { - // skip leading `/` - path.chars().skip(1).collect::() + // skip the leading `/`, if it starts with one. + path.strip_prefix('/').unwrap_or(path.as_str()).to_string() }; let mut asset_path = AssetKey::from(path.as_str());