Fixes path, image, and bibliography issues #7

Merged
AlexKucera merged 19 commits from windows_path_fix into master 2025-11-05 09:28:22 +01:00
Showing only changes of commit 711eab4593 - Show all commits
+8 -5
View File
1
@@ -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);
coderabbitai[bot] commented 2025-11-04 11:24:46 +01:00 (Migrated from github.com)
Review

⚠️ Potential issue | 🟠 Major

Preserve original image extensions instead of forcing .png.

When a remote file ends with something like .svg, we append .png without converting the contents. That leaves us with an SVG payload masquerading as PNG, so Typst/Pandoc will fail to decode the asset. Please keep the on-disk extension if one is present (at least include .svg, .ico, etc. in validExtensions, or only fall back to .png when the URL truly lacks an extension). Based on learnings

🤖 Prompt for AI Agents
In src/plugin/EmbedProcessor.ts around lines 96 to 103, the current logic forces
a .png when the file extension isn't in a small whitelist, which causes
mismatched on-disk extensions for assets like .svg or .ico; change the logic to
preserve any existing extension returned by path.extname (after normalizing and
stripping query/fragments) and only append .png when no extension is present (or
the ext is empty), or alternatively expand the validExtensions list to include
common types like .svg, .ico, .avif, .svgz; ensure you normalize ext via
toLowerCase() and treat extensions with query strings correctly so the
finalFileName uses the original extension when present and only falls back to
.png when the URL truly lacks one.

✅ Addressed in commits 7ac9e1f to 4eb52d1

_⚠️ Potential issue_ | _🟠 Major_ **Preserve original image extensions instead of forcing `.png`.** When a remote file ends with something like `.svg`, we append `.png` without converting the contents. That leaves us with an SVG payload masquerading as PNG, so Typst/Pandoc will fail to decode the asset. Please keep the on-disk extension if one is present (at least include `.svg`, `.ico`, etc. in `validExtensions`, or only fall back to `.png` when the URL truly lacks an extension). Based on learnings <details> <summary>🤖 Prompt for AI Agents</summary> ``` In src/plugin/EmbedProcessor.ts around lines 96 to 103, the current logic forces a .png when the file extension isn't in a small whitelist, which causes mismatched on-disk extensions for assets like .svg or .ico; change the logic to preserve any existing extension returned by path.extname (after normalizing and stripping query/fragments) and only append .png when no extension is present (or the ext is empty), or alternatively expand the validExtensions list to include common types like .svg, .ico, .avif, .svgz; ensure you normalize ext via toLowerCase() and treat extensions with query strings correctly so the finalFileName uses the original extension when present and only falls back to .png when the URL truly lacks one. ``` </details> <!-- fingerprinting:phantom:medusa:sabertoothed --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commits 7ac9e1f to 4eb52d1
1