Skip to content

Commit 39f202e

Browse files
committed
Recognize .bmp, .tiff, .tif, and .ico as supported image files
1 parent c325d14 commit 39f202e

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

app/src/util/openable_file_type.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub fn is_supported_image_file(path: impl AsRef<Path>) -> bool {
7575
.map(|ext| {
7676
matches!(
7777
ext.to_ascii_lowercase().as_str(),
78-
"jpg" | "jpeg" | "png" | "gif" | "webp" | "svg"
78+
"jpg" | "jpeg" | "png" | "gif" | "bmp" | "tiff" | "tif" | "webp" | "ico" | "svg"
7979
)
8080
})
8181
.unwrap_or(false)
@@ -344,4 +344,36 @@ mod tests {
344344
assert!(!is_supported_code_file(Path::new("data.txt")));
345345
assert!(!is_supported_code_file(Path::new("image.png")));
346346
}
347+
348+
/// `is_supported_image_file` should agree with the image extensions in
349+
/// `warp_util::file_type::is_binary_file`, otherwise binary image files
350+
/// like `.bmp` / `.tiff` / `.ico` get rejected by `is_file_openable_in_warp`
351+
/// without ever being routed to `FileTarget::SystemGeneric`, leaving the
352+
/// click-to-open path with no working target.
353+
#[test]
354+
fn test_is_supported_image_file_covers_common_formats() {
355+
for name in [
356+
"photo.jpg",
357+
"photo.jpeg",
358+
"photo.png",
359+
"icon.gif",
360+
"screenshot.bmp",
361+
"scan.tiff",
362+
"scan.tif",
363+
"asset.webp",
364+
"favicon.ico",
365+
"logo.svg",
366+
] {
367+
assert!(
368+
is_supported_image_file(Path::new(name)),
369+
"{name} should be recognized as an image file"
370+
);
371+
}
372+
// Case-insensitive on the extension.
373+
assert!(is_supported_image_file(Path::new("photo.PNG")));
374+
assert!(is_supported_image_file(Path::new("scan.TIFF")));
375+
// Sanity: non-image extensions are still rejected.
376+
assert!(!is_supported_image_file(Path::new("readme.md")));
377+
assert!(!is_supported_image_file(Path::new("script.rs")));
378+
}
347379
}

0 commit comments

Comments
 (0)