wgui: parser: normalize paths in <include>s, (fix rust-embed file not found in release build)

This commit is contained in:
Aleksander
2025-09-22 14:31:49 +02:00
parent 4afdde1793
commit 5e6852e5d0
3 changed files with 23 additions and 3 deletions

View File

@@ -1,3 +1,22 @@
use std::path::{Path, PathBuf};
pub trait AssetProvider {
fn load_from_path(&mut self, path: &str) -> anyhow::Result<Vec<u8>>;
}
// replace "./foo/bar/../file.txt" with "./foo/file.txt"
pub fn normalize_path(path: &Path) -> PathBuf {
let mut stack = Vec::new();
for component in path.components() {
match component {
std::path::Component::ParentDir => {
stack.pop();
}
std::path::Component::Normal(name) => {
stack.push(name);
}
_ => {}
}
}
stack.iter().collect()
}