fix(pdf): export no longer fails on names with å/ä/ö or emoji in the file name (1.89.19)
This commit is contained in:
1 parent
eefef11aaa
commit
da20a7e978
5 files changed
+29
-4
No files matched your search
@@ -665,7 +665,7 @@ app.post("/api/export/pdf", (req, res) => {
|
||||
const payload = normalizePdfExportPayload(req.body || {});
|
||||
const pdf = buildStyledPdf(payload);
|
||||
res.setHeader("Content-Type", "application/pdf");
|
||||
res.setHeader("Content-Disposition", `attachment; filename="${payload.filename}"`);
|
||||
res.setHeader("Content-Disposition", attachmentDisposition(payload.filename));
|
||||
res.send(pdf);
|
||||
} catch (error) {
|
||||
res.status(400).json({ error: error instanceof Error ? error.message : String(error) });
|
||||
@@ -898,6 +898,15 @@ function readStoredAppState() {
|
||||
return { state: JSON.parse(row.state_json), updatedAt: row.updated_at };
|
||||
}
|
||||
|
||||
// A header may only hold plain ASCII: a race named "Höstcupen" or "Open #Test2 🏁" made the
|
||||
// export fail with "Invalid character in header content". ASCII fallback for old clients,
|
||||
// plus the real name encoded (RFC 6266/5987) for every current browser.
|
||||
function attachmentDisposition(filename) {
|
||||
const name = String(filename || "export.pdf");
|
||||
const ascii = name.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").replace(/[^\x20-\x7e]/gu, "_").replace(/["\\]/g, "_") || "export.pdf";
|
||||
return `attachment; filename="${ascii}"; filename*=UTF-8''${encodeURIComponent(name)}`;
|
||||
}
|
||||
|
||||
function normalizePdfExportPayload(input = {}) {
|
||||
const title = String(input.title || "RC RaceCore").trim();
|
||||
const subtitle = String(input.subtitle || "").trim();
|
||||
|
||||
Reference in new issue
Block a user