Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion app/src/util/openable_file_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn is_supported_image_file(path: impl AsRef<Path>) -> bool {
.map(|ext| {
matches!(
ext.to_ascii_lowercase().as_str(),
"jpg" | "jpeg" | "png" | "gif" | "webp" | "svg"
"jpg" | "jpeg" | "png" | "gif" | "bmp" | "tiff" | "tif" | "webp" | "ico" | "svg"
)
})
.unwrap_or(false)
Expand Down Expand Up @@ -344,4 +344,36 @@ mod tests {
assert!(!is_supported_code_file(Path::new("data.txt")));
assert!(!is_supported_code_file(Path::new("image.png")));
}

/// `is_supported_image_file` should agree with the image extensions in
/// `warp_util::file_type::is_binary_file`, otherwise binary image files
/// like `.bmp` / `.tiff` / `.ico` get rejected by `is_file_openable_in_warp`
/// without ever being routed to `FileTarget::SystemGeneric`, leaving the
/// click-to-open path with no working target.
#[test]
fn test_is_supported_image_file_covers_common_formats() {
for name in [
"photo.jpg",
"photo.jpeg",
"photo.png",
"icon.gif",
"screenshot.bmp",
"scan.tiff",
"scan.tif",
"asset.webp",
"favicon.ico",
"logo.svg",
] {
assert!(
is_supported_image_file(Path::new(name)),
"{name} should be recognized as an image file"
);
}
// Case-insensitive on the extension.
assert!(is_supported_image_file(Path::new("photo.PNG")));
assert!(is_supported_image_file(Path::new("scan.TIFF")));
// Sanity: non-image extensions are still rejected.
assert!(!is_supported_image_file(Path::new("readme.md")));
assert!(!is_supported_image_file(Path::new("script.rs")));
}
}