From c4b28b04e3c0ce369db6ce10fc0acf8f70b54abb Mon Sep 17 00:00:00 2001 From: Uli-Z Date: Wed, 2 Jul 2025 10:41:56 +0200 Subject: [PATCH] fix: Resolve 500 error on CSV export for group names with umlauts Previously, exporting groups with German umlauts in their names resulted in a 500 error due to incorrect handling of the header. This commit corrects the usage of the library to properly generate both ASCII (fallback) and UTF-8 (full) compatible filenames, ensuring successful CSV exports for all group names. Fixes #458 --- .../groups/[groupId]/expenses/export/csv/route.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/app/groups/[groupId]/expenses/export/csv/route.ts b/src/app/groups/[groupId]/expenses/export/csv/route.ts index dfb92c7b5..46b7ae1b5 100644 --- a/src/app/groups/[groupId]/expenses/export/csv/route.ts +++ b/src/app/groups/[groupId]/expenses/export/csv/route.ts @@ -151,13 +151,23 @@ export async function GET( const csv = json2csvParser.parse(expenses) const date = new Date().toISOString().split('T')[0] - const filename = `Spliit Export - ${group.name} - ${date}.csv` + + // Create an ASCII-safe version of the group name for the 'filename' parameter + const asciiSafeGroupName = group.name.replace(/[^\x00-\x7F]/g, '_') // Replace non-ASCII with underscore + const asciiFilename = `Spliit Export - ${asciiSafeGroupName} - ${date}.csv` + + // Use the original group name for the 'filename*' parameter (UTF-8 encoded) + const fullFilename = `Spliit Export - ${group.name} - ${date}.csv` + const encodedFullFilename = encodeURIComponent(fullFilename) // \uFEFF character is added at the beginning of the CSV content to ensure that it is interpreted as UTF-8 with BOM (Byte Order Mark), which helps some applications correctly interpret the encoding. return new NextResponse(`\uFEFF${csv}`, { headers: { 'Content-Type': 'text/csv; charset=utf-8', - 'Content-Disposition': contentDisposition(filename), + 'Content-Disposition': contentDisposition(fullFilename, { + type: 'attachment', + fallback: asciiFilename, + }), }, }) }