From 88cf7f38e23c0620f7e356125d3c50446f90cecb Mon Sep 17 00:00:00 2001 From: Riccardo Giorato Date: Thu, 29 Jan 2026 22:04:04 +0100 Subject: [PATCH] Update route.ts --- app/api/download-pdf/route.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/api/download-pdf/route.ts b/app/api/download-pdf/route.ts index 4990e35..a0b41ea 100644 --- a/app/api/download-pdf/route.ts +++ b/app/api/download-pdf/route.ts @@ -75,11 +75,17 @@ export async function GET(request: NextRequest) { const pdfBuffer = Buffer.from(pdf.output("arraybuffer")); + // Sanitize filename to only contain ASCII characters + const safeFilename = story.title + .replace(/[^\x00-\x7F]/g, "") // Remove non-ASCII characters + .replace(/[<>:"/\\|?*]/g, "-") // Replace invalid filename characters + .trim() || "comic"; + // Return PDF as response return new NextResponse(pdfBuffer, { headers: { "Content-Type": "application/pdf", - "Content-Disposition": `attachment; filename="${story.title}.pdf"`, + "Content-Disposition": `attachment; filename="${safeFilename}.pdf"`, }, }); } catch (error) {