Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/app/groups/[groupId]/expenses/export/csv/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
},
})
}
Loading