mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-05 10:13:00 +02:00
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:
6
.changes/fix-get-asset-no-leading-slash.md
Normal file
6
.changes/fix-get-asset-no-leading-slash.md
Normal 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 (/).
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user