Skip to content

Commit 3aef860

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 3b83a5f commit 3aef860

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
@@ -150,13 +150,23 @@ export async function GET(
150150
const csv = json2csvParser.parse(expenses)
151151

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

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

0 commit comments

Comments
 (0)