mirror of
https://github.com/Tony0410/nextstep.git
synced 2026-05-24 13:21:39 +08:00
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:
@@ -56,11 +56,17 @@ export async function GET(
|
||||
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, {
|
||||
status: 200,
|
||||
headers: {
|
||||
'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',
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user