Fix iCal endpoint crash from non-ASCII characters in workspace name

The Content-Disposition header was including the workspace name directly,
causing a "Cannot convert argument to ByteString" error when workspace
names contained smart apostrophes or other non-ASCII characters (e.g.,
"Grace's Plan" with curly apostrophe U+2019).

Sanitize filename by removing non-ASCII characters before using in header.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Gemini Agent
2026-01-23 20:34:00 +00:00
parent 3034d52884
commit e5db48f82b

View File

@@ -56,11 +56,17 @@ export async function GET(
membership.workspace.name membership.workspace.name
) )
// Sanitize filename for HTTP headers (remove non-ASCII characters)
const safeFilename = membership.workspace.name
.replace(/[^\x00-\x7F]/g, '') // Remove non-ASCII
.replace(/[<>:"/\\|?*]/g, '-') // Replace invalid filename chars
.trim() || 'appointments'
return new NextResponse(icalContent, { return new NextResponse(icalContent, {
status: 200, status: 200,
headers: { headers: {
'Content-Type': 'text/calendar; charset=utf-8', 'Content-Type': 'text/calendar; charset=utf-8',
'Content-Disposition': `attachment; filename="${membership.workspace.name}-appointments.ics"`, 'Content-Disposition': `attachment; filename="${safeFilename}-appointments.ics"`,
'Cache-Control': 'no-cache, no-store, must-revalidate', 'Cache-Control': 'no-cache, no-store, must-revalidate',
}, },
}) })