diff --git a/crates/bevy_asset/src/path.rs b/crates/bevy_asset/src/path.rs index e61e27e5dc..b5eda7866f 100644 --- a/crates/bevy_asset/src/path.rs +++ b/crates/bevy_asset/src/path.rs @@ -448,10 +448,19 @@ impl<'a> AssetPath<'a> { /// Returns the full extension (including multiple '.' values). /// Ex: Returns `"config.ron"` for `"my_asset.config.ron"` + /// + /// Also strips out anything following a `?` to handle query parameters in URIs pub fn get_full_extension(&self) -> Option { let file_name = self.path().file_name()?.to_str()?; let index = file_name.find('.')?; - let extension = file_name[index + 1..].to_lowercase(); + let mut extension = file_name[index + 1..].to_lowercase(); + + // Strip off any query parameters + let query = extension.find('?'); + if let Some(offset) = query { + extension.truncate(offset); + } + Some(extension) } @@ -930,5 +939,8 @@ mod tests { let result = AssetPath::from("http://a#Foo"); assert_eq!(result.get_full_extension(), None); + + let result = AssetPath::from("http://a.tar.bz2?foo=bar#Baz"); + assert_eq!(result.get_full_extension(), Some("tar.bz2".to_string())); } }