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
@@ -8,6 +8,12 @@ The application version is maintained in `package.json` and displayed in the adm
|
||||
|
||||
No changes recorded yet.
|
||||
|
||||
## 1.89.19 - 2026-11-13
|
||||
|
||||
### Fixed
|
||||
|
||||
- PDF export failed with "Invalid character in header content" when the race, heat or series name had å/ä/ö, an emoji or other non-ASCII characters. The file keeps its real name.
|
||||
|
||||
## 1.89.18 - 2026-11-13
|
||||
|
||||
### Added
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "rc-racecore",
|
||||
"version": "1.89.18",
|
||||
"version": "1.89.19",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "rc-racecore",
|
||||
"version": "1.89.18",
|
||||
"version": "1.89.19",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"better-sqlite3": "^12.11.1",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "rc-racecore",
|
||||
"version": "1.89.18",
|
||||
"version": "1.89.19",
|
||||
"private": true,
|
||||
"description": "RC RaceCore live timing and race control with AMMC ingest and SQLite persistence",
|
||||
"engines": {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -517,6 +517,16 @@ test("PDF export renders Swedish åäö/ÅÄÖ correctly instead of mojibake", {
|
||||
});
|
||||
assert.equal(response.status, 200);
|
||||
assert.equal(response.headers.get("content-type"), "application/pdf");
|
||||
// A file name with å/ä/ö, # or an emoji may not break the header ("Invalid character in header content").
|
||||
const named = await fetch(`${baseUrl}/api/export/pdf`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ title: "x", filename: "Höstcupen_Open_#Test2_🏁_A-final.pdf", sections: [{ title: "x", headers: ["a"], rows: [["b"]] }] }),
|
||||
});
|
||||
assert.equal(named.status, 200);
|
||||
const disposition = named.headers.get("content-disposition");
|
||||
assert.match(disposition, /filename="Hostcupen_Open_#Test2___A-final\.pdf"/);
|
||||
assert.match(disposition, /filename\*=UTF-8''H%C3%B6stcupen/);
|
||||
const pdfBuffer = Buffer.from(await response.arrayBuffer());
|
||||
|
||||
// The font must declare WinAnsiEncoding - without it a PDF viewer falls back to a standard
|
||||
|
||||
Reference in new issue
Block a user