mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-07 00:40:10 -06:00
fix: fixes encoding of file name (#1712)
This commit is contained in:
@@ -16,6 +16,11 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
const { json, fields, fileName } = data;
|
||||
|
||||
const fallbackFileName = fileName.replace(/[^A-Za-z0-9_.-]/g, "_");
|
||||
const encodedFileName = encodeURIComponent(fileName)
|
||||
.replace(/['()]/g, (match) => "%" + match.charCodeAt(0).toString(16))
|
||||
.replace(/\*/g, "%2A");
|
||||
|
||||
const parser = new AsyncParser({
|
||||
fields,
|
||||
});
|
||||
@@ -29,7 +34,10 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
const headers = new Headers();
|
||||
headers.set("Content-Type", "text/csv;charset=utf-8;");
|
||||
headers.set("Content-Disposition", `attachment; filename=${fileName ?? "converted"}.csv`);
|
||||
headers.set(
|
||||
"Content-Disposition",
|
||||
`attachment; filename="${fallbackFileName}"; filename*=UTF-8''${encodedFileName}`
|
||||
);
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
|
||||
@@ -15,6 +15,11 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
const { json, fields, fileName } = data;
|
||||
|
||||
const fallbackFileName = fileName.replace(/[^A-Za-z0-9_.-]/g, "_");
|
||||
const encodedFileName = encodeURIComponent(fileName)
|
||||
.replace(/['()]/g, (match) => "%" + match.charCodeAt(0).toString(16))
|
||||
.replace(/\*/g, "%2A");
|
||||
|
||||
const wb = xlsx.utils.book_new();
|
||||
const ws = xlsx.utils.json_to_sheet(json, { header: fields });
|
||||
xlsx.utils.book_append_sheet(wb, ws, "Sheet1");
|
||||
@@ -23,8 +28,12 @@ export async function POST(request: NextRequest) {
|
||||
const base64String = buffer.toString("base64");
|
||||
|
||||
const headers = new Headers();
|
||||
|
||||
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
headers.set("Content-Disposition", `attachment; filename=${fileName ?? "converted"}.xlsx`);
|
||||
headers.set(
|
||||
"Content-Disposition",
|
||||
`attachment; filename="${fallbackFileName}"; filename*=UTF-8''${encodedFileName}`
|
||||
);
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user