Skip to content
Merged
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
24 changes: 23 additions & 1 deletion src/components/Dialogs/ImageDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,29 @@ export function ImageDialog() {
}, []);

// ── Compute preview URL (either file preview or typed URL) ─
const previewSrc = source === 'file' ? filePreview : url.trim() || null;
const getSafePreviewSrc = (): string | null => {
if (source === 'file') {
return filePreview;
}

const trimmed = url.trim();
if (!trimmed) {
return null;
}

try {
const parsed = new URL(trimmed, window.location.origin);
const scheme = parsed.protocol.replace(':', '').toLowerCase();
if (scheme === 'http' || scheme === 'https' || scheme === 'data') {
return trimmed;
}
return null;
} catch {
return null;
}
};

const previewSrc = getSafePreviewSrc();
const showPreview = !!previewSrc;

return (
Expand Down
Loading