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](c860b0f4c6/packages/target-tauri/src-tauri/src/help_window.rs (L34-L43)).
This commit is contained in:
WofWca
2025-03-14 07:29:55 +04:00
committed by GitHub
parent d8059bad3c
commit f67a4a6bfe
2 changed files with 8 additions and 2 deletions

View File

@@ -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 (/).

View File

@@ -397,8 +397,8 @@ impl<R: Runtime> AppManager<R> {
// if the url is `tauri://localhost`, we should load `index.html`
"index.html".to_string()
} else {
// skip leading `/`
path.chars().skip(1).collect::<String>()
// 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());