diff --git a/crates/bevy_asset/src/path.rs b/crates/bevy_asset/src/path.rs index de9dfa5ca583a..4d8d647940000 100644 --- a/crates/bevy_asset/src/path.rs +++ b/crates/bevy_asset/src/path.rs @@ -648,7 +648,13 @@ pub(crate) fn normalize_path(path: &Path) -> PathBuf { if elt == "." { // Skip } else if elt == ".." { - if !result_path.pop() { + // Note: If the result_path ends in `..`, Path::file_name returns None, so we'll end up + // preserving it. + if result_path.file_name().is_some() { + // This assert is just a sanity check - we already know the path has a file_name, so + // we know there is something to pop. + assert!(result_path.pop()); + } else { // Preserve ".." if insufficient matches (per RFC 1808). result_path.push(elt); } @@ -996,6 +1002,24 @@ mod tests { ); } + #[test] + fn resolve_embed_relative_to_external_path() { + let base = AssetPath::from("../../a/b.gltf"); + assert_eq!( + base.resolve_embed("c.bin").unwrap(), + AssetPath::from("../../a/c.bin") + ); + } + + #[test] + fn resolve_relative_to_external_path() { + let base = AssetPath::from("../../a/b.gltf"); + assert_eq!( + base.resolve("c.bin").unwrap(), + AssetPath::from("../../a/b.gltf/c.bin") + ); + } + #[test] fn test_get_extension() { let result = AssetPath::from("http://a.tar.gz#Foo");