From 683050c92703365b826027f3a2f9ba499926f8af Mon Sep 17 00:00:00 2001 From: Leon Date: Mon, 13 Jul 2026 17:55:01 +0800 Subject: [PATCH] fix: handle RFC 5987 filename*=UTF-8'' encoding in printPdf Previous regex matched 'UTF-8' as filename when Content-Disposition used extended notation. Now try filename*=UTF-8'' first, then fall back to plain filename="...". --- docutranslate/static/index.html | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docutranslate/static/index.html b/docutranslate/static/index.html index ad1ef00..62660d9 100644 --- a/docutranslate/static/index.html +++ b/docutranslate/static/index.html @@ -2006,8 +2006,15 @@ const ifr = document.getElementById('printFrame'); fetch(url).then(r => { const cd = r.headers.get('content-disposition') || ''; - const match = cd.match(/filename[^;=\n]*=['"]?([^'"\n;]+)['"]?/i); - const printTitle = match ? match[1].replace(/\.[^.]+$/, '') : ''; + // RFC 5987: filename*=UTF-8'' + const extMatch = cd.match(/filename\*\s*=\s*UTF-8''([^;\s]+)/i); + let printTitle = ''; + if (extMatch) { + try { printTitle = decodeURIComponent(extMatch[1]).replace(/\.[^.]+$/, ''); } catch(e) {} + } else { + const plainMatch = cd.match(/filename\s*=\s*["']?([^"'\n;]+)["']?/i); + if (plainMatch) printTitle = plainMatch[1].trim().replace(/\.[^.]+$/, ''); + } return r.text().then(h => ({ h, printTitle })); }).then(({ h, printTitle }) => { ifr.srcdoc = h;