Skip to content

Commit f67a4a6

Browse files
authored
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).
1 parent d8059ba commit f67a4a6

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'tauri': 'patch:bug'
3+
---
4+
5+
Fix `tauri::AssetResolver::get` and `tauri::AssetResolver::get_for_scheme`
6+
skipping the first character of the `path` even if it's not a slash (/).

crates/tauri/src/manager/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ impl<R: Runtime> AppManager<R> {
397397
// if the url is `tauri://localhost`, we should load `index.html`
398398
"index.html".to_string()
399399
} else {
400-
// skip leading `/`
401-
path.chars().skip(1).collect::<String>()
400+
// skip the leading `/`, if it starts with one.
401+
path.strip_prefix('/').unwrap_or(path.as_str()).to_string()
402402
};
403403

404404
let mut asset_path = AssetKey::from(path.as_str());

0 commit comments

Comments
 (0)