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''<percent-encoded>
first, then fall back to plain filename="...".
This commit is contained in:
2026-07-13 17:55:01 +08:00
parent e4641aee58
commit 683050c927

View File

@@ -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''<percent-encoded>
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;