Skip to content

Commit c4b28b0

Browse files
committed
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
1 parent d3b151e commit c4b28b0

File tree

1 file changed

+12
-2
lines changed
  • src/app/groups/[groupId]/expenses/export/csv

1 file changed

+12
-2
lines changed

src/app/groups/[groupId]/expenses/export/csv/route.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,23 @@ export async function GET(
151151
const csv = json2csvParser.parse(expenses)
152152

153153
const date = new Date().toISOString().split('T')[0]
154-
const filename = `Spliit Export - ${group.name} - ${date}.csv`
154+
155+
// Create an ASCII-safe version of the group name for the 'filename' parameter
156+
const asciiSafeGroupName = group.name.replace(/[^\x00-\x7F]/g, '_') // Replace non-ASCII with underscore
157+
const asciiFilename = `Spliit Export - ${asciiSafeGroupName} - ${date}.csv`
158+
159+
// Use the original group name for the 'filename*' parameter (UTF-8 encoded)
160+
const fullFilename = `Spliit Export - ${group.name} - ${date}.csv`
161+
const encodedFullFilename = encodeURIComponent(fullFilename)
155162

156163
// \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.
157164
return new NextResponse(`\uFEFF${csv}`, {
158165
headers: {
159166
'Content-Type': 'text/csv; charset=utf-8',
160-
'Content-Disposition': contentDisposition(filename),
167+
'Content-Disposition': contentDisposition(fullFilename, {
168+
type: 'attachment',
169+
fallback: asciiFilename,
170+
}),
161171
},
162172
})
163173
}

0 commit comments

Comments
 (0)