Skip to content

Commit 709fdc2

Browse files
Sync blocklist image extensions with is_binary_file (#9397)
## Description Follow-up to #9395 in a different file. While auditing image-extension lists across the repo I found a third copy in `is_supported_blocklist_image_source` (`app/src/ai/blocklist/block/view_impl/common.rs`) that suffers from the exact same drift: it only matches `jpg | jpeg | png | gif | webp | svg`, missing `.bmp`, `.tiff` / `.tif`, and `.ico`. So inline references to local `.bmp` / `.tiff` / `.ico` images in agent block output fail the support check and don't render as the inline image — they silently fall back to plain text — even though the same files do route to the system viewer once #9395 lands. ```diff - "jpg" | "jpeg" | "png" | "gif" | "webp" | "svg" + "jpg" | "jpeg" | "png" | "gif" | "bmp" | "tiff" | "tif" | "webp" | "ico" | "svg" ``` The full picture, for context: | Location | What it does | Pre-fix | |---|---|---| | `crates/warp_util/src/file_type.rs` (`is_binary_file`) | Canonical binary-file extension list | 9 image formats | | `app/src/util/openable_file_type.rs` (`is_supported_image_file`) | Routes click-to-open to `FileTarget::SystemGeneric` | 6 formats — fixed in #9395 | | **This PR** — `app/src/ai/blocklist/block/view_impl/common.rs` (`is_supported_blocklist_image_source`) | Gates inline rendering of agent block image references | 6 formats | | `crates/warpui_core/src/platform/file_picker.rs` (`FileType::Image`) | Theme-creator file-picker filter | 3 formats — left for a separate PR; the right "what should be selectable as a theme background" set is more subjective | ## Testing - Added `is_supported_blocklist_image_source_covers_common_local_formats` in `common_tests.rs`. Asserts every supported extension passes (10 cases), case-insensitivity (`PHOTO.PNG`, `scan.TIFF`), and that HTTP / HTTPS sources and non-image extensions still return false. Fails on master for the four new extensions, passes after the change. - `cargo fmt -p warp -- --check` passes locally. - Couldn't run `cargo nextest` locally because the Metal toolchain isn't installed (same caveat as #9277, #9345, #9346, #9395) — relying on CI for the full clippy / nextest pass. ## Related - #9395 — same fix for `is_supported_image_file` (file-open routing path). ## Changelog Entries for Stable CHANGELOG-BUG-FIX: Inline `.bmp`, `.tiff` / `.tif`, and `.ico` images in agent block output now render correctly instead of falling back to plain text. Co-authored-by: anshul-garg27 <anshul-garg27@users.noreply.github.com>
1 parent 7784428 commit 709fdc2

2 files changed

Lines changed: 44 additions & 4 deletions

File tree

‎app/src/ai/blocklist/block/view_impl/common.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2312,7 +2312,7 @@ fn is_supported_blocklist_image_source(source: &str) -> bool {
23122312
.map(|ext| {
23132313
matches!(
23142314
ext.to_ascii_lowercase().as_str(),
2315-
"jpg" | "jpeg" | "png" | "gif" | "webp" | "svg"
2315+
"jpg" | "jpeg" | "png" | "gif" | "bmp" | "tiff" | "tif" | "webp" | "ico" | "svg"
23162316
)
23172317
})
23182318
.unwrap_or(false)

‎app/src/ai/blocklist/block/view_impl/common_tests.rs‎

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use warpui::App;
1010
use super::{blocklist_image_asset_source, ResolvedBlocklistImageSources};
1111
use super::{
1212
collect_visual_markdown_lightbox_collection, compute_visual_section_width,
13-
inline_image_source_label, lightbox_trigger_for_section, query_prefix_highlight_len,
14-
render_scrollable_collapsible_content, text_sections_with_indices, CollapsibleElementState,
15-
CollapsibleExpansionState, VisualMarkdownLightboxCollection,
13+
inline_image_source_label, is_supported_blocklist_image_source, lightbox_trigger_for_section,
14+
query_prefix_highlight_len, render_scrollable_collapsible_content, text_sections_with_indices,
15+
CollapsibleElementState, CollapsibleExpansionState, VisualMarkdownLightboxCollection,
1616
};
1717
use crate::{
1818
ai::agent::{
@@ -292,3 +292,43 @@ fn blocklist_image_asset_source_uses_cached_resolution_when_available() {
292292
other => panic!("expected cached local file asset source, got {other:?}"),
293293
}
294294
}
295+
296+
/// `is_supported_blocklist_image_source` should accept the same image extensions
297+
/// that `warp_util::file_type::is_binary_file` recognises (plus `svg`, which is
298+
/// text/XML and not in `is_binary_file`). Until #9395 / this fix landed the
299+
/// blocklist list was only `jpg | jpeg | png | gif | webp | svg`, so inline
300+
/// references to local `.bmp` / `.tiff` / `.tif` / `.ico` images failed the
301+
/// support check and silently rendered as plain text.
302+
#[test]
303+
fn is_supported_blocklist_image_source_covers_common_local_formats() {
304+
for source in [
305+
"diagram.jpg",
306+
"diagram.jpeg",
307+
"diagram.png",
308+
"diagram.gif",
309+
"diagram.bmp",
310+
"diagram.tiff",
311+
"diagram.tif",
312+
"diagram.webp",
313+
"diagram.ico",
314+
"diagram.svg",
315+
] {
316+
assert!(
317+
is_supported_blocklist_image_source(source),
318+
"{source} should be a supported local image source"
319+
);
320+
}
321+
// Case-insensitive on the extension.
322+
assert!(is_supported_blocklist_image_source("PHOTO.PNG"));
323+
assert!(is_supported_blocklist_image_source("scan.TIFF"));
324+
// HTTP / HTTPS sources are intentionally rejected regardless of extension.
325+
assert!(!is_supported_blocklist_image_source(
326+
"http://example.com/x.png"
327+
));
328+
assert!(!is_supported_blocklist_image_source(
329+
"https://example.com/x.png"
330+
));
331+
// Non-image extensions stay rejected.
332+
assert!(!is_supported_blocklist_image_source("doc.pdf"));
333+
assert!(!is_supported_blocklist_image_source("notes.md"));
334+
}

0 commit comments

Comments
 (0)