From 711eab4593b3ae45c822aad183672c1425fd04f0 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Wed, 5 Nov 2025 08:05:40 +0100 Subject: [PATCH] Handles images without extensions correctly Ensures images without file extensions are properly handled by appending ".png" to the filename, preventing potential issues with image processing or display. Preserves existing extensions for other image types (e.g., svg, ico, avif) without forcing a ".png" extension. --- src/plugin/EmbedProcessor.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/plugin/EmbedProcessor.ts b/src/plugin/EmbedProcessor.ts index d8c7fb7..df66cce 100644 --- a/src/plugin/EmbedProcessor.ts +++ b/src/plugin/EmbedProcessor.ts @@ -91,14 +91,17 @@ export class EmbedProcessor { // Parse URL to get filename const urlObj = new URL(imageUrl); const urlPath = urlObj.pathname; - const fileName = path.basename(urlPath) || `remote-image-${Date.now()}.png`; + const fileName = path.basename(urlPath) || `remote-image-${Date.now()}`; // Ensure we have a valid file extension + // Extract extension and normalize it (lowercase) const ext = path.extname(fileName).toLowerCase(); - const validExtensions = ['.png', '.jpg', '.jpeg', '.gif', '.webp', '.bmp', '.tiff']; - const finalFileName = validExtensions.includes(ext) - ? fileName - : `${fileName}.png`; + + // Preserve any existing extension, or append .png if no extension present + // This handles all image types (svg, ico, avif, etc.) without forcing .png + const finalFileName = ext + ? fileName // Has an extension, preserve it + : `${fileName}.png`; // No extension, append .png const outputPath = path.join(tempDir, finalFileName);