From dec80ab41466005656a12057aced096fd60a6888 Mon Sep 17 00:00:00 2001 From: Baptiste LAFOURCADE Date: Tue, 28 Jul 2026 05:11:29 +0200 Subject: [PATCH] fix(intake): parse the HTML form GitHub now inserts for photos Dragging an image into an Issue Form textarea used to produce markdown `![](url)`; GitHub now inserts ``. extractImageUrl only matched markdown, so it fell back to the bare-URL regex and captured the URL with the trailing `"` -> photo download 404 -> intake crash. Add an `` case and stop the bare-URL match at delimiters (quotes, angle brackets, parens). Tests cover the exact failing payload. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01PC9TRnYr5AXe7GmBmHjkBy --- .github/scripts/lib/photo-url.mjs | 10 ++++++++-- .github/scripts/lib/photo-url.test.mjs | 9 +++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/scripts/lib/photo-url.mjs b/.github/scripts/lib/photo-url.mjs index 13c3c55..720811f 100644 --- a/.github/scripts/lib/photo-url.mjs +++ b/.github/scripts/lib/photo-url.mjs @@ -1,11 +1,17 @@ // Extraction d'URL d'image — pur, sans dépendance (pas de sharp). // Le chemin de la photo sur disque vit dans member-paths.mjs. -/** Extrait l'URL d'image d'un champ Issue Form (markdown ![alt](url) ou URL nue). */ +/** Extrait l'URL d'image d'un champ Issue Form. + * Gère les trois formes : markdown `![alt](url)`, balise HTML `` + * (le drag-drop GitHub insère désormais ça), et URL nue. */ export function extractImageUrl(field) { const text = String(field ?? ''); const md = text.match(/!\[[^\]]*\]\((https?:\/\/[^)\s]+)\)/); if (md) return md[1]; - const bare = text.match(/https?:\/\/\S+/); + const html = text.match(/]*\bsrc\s*=\s*["']([^"']+)["']/i); + if (html) return html[1]; + // URL nue : s'arrête aux délimiteurs (guillemets, chevrons, parenthèses) pour ne pas + // capter un caractère de fin de balise/markdown collé à l'URL. + const bare = text.match(/https?:\/\/[^\s"'<>)]+/); return bare ? bare[0] : null; } diff --git a/.github/scripts/lib/photo-url.test.mjs b/.github/scripts/lib/photo-url.test.mjs index 4533320..ab7ba07 100644 --- a/.github/scripts/lib/photo-url.test.mjs +++ b/.github/scripts/lib/photo-url.test.mjs @@ -23,4 +23,13 @@ describe('extractImageUrl', () => { const url = extractImageUrl('texte https://autre.com ![x](https://vrai.com/i.webp)'); assert.equal(url, 'https://vrai.com/i.webp'); }); + + it('extrait l\'URL d\'une balise HTML (drag-drop GitHub actuel), sans le guillemet', () => { + const field = 'Image'; + assert.equal(extractImageUrl(field), 'https://github.com/user-attachments/assets/6451b1af-c883-4151-9836-acfd1dae5d25'); + }); + + it('n\'attrape pas un guillemet/chevron collé à une URL nue', () => { + assert.equal(extractImageUrl('src="https://example.com/c.png"'), 'https://example.com/c.png'); + }); });