Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions packages/app/src/utils/session-export.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ describe("sessionExportFilename", () => {
test("falls back to id when title and slug are empty", () => {
expect(sessionExportFilename({ id: "ses_123" })).toBe("ses_123.json")
})

test("limits filename length while preserving the extension", () => {
const filename = sessionExportFilename({ id: "ses_123", title: "x".repeat(300) })

expect(filename).toBe(`${"x".repeat(250)}.json`)
expect(new TextEncoder().encode(filename)).toHaveLength(255)
})
})

describe("fetchSessionExport", () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/app/src/utils/session-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export type SessionExportClient = {
}
}

const MAX_EXPORT_BASENAME_LENGTH = 250

export async function fetchSessionExport(input: {
sessionID: string
client: SessionExportClient
Expand Down Expand Up @@ -43,6 +45,7 @@ export function sessionExportFilename(session: { id: string; title?: string; slu
const clean = name
.toLowerCase()
.replace(/[^a-z0-9_-]+/gi, "-")
.slice(0, MAX_EXPORT_BASENAME_LENGTH)
.replace(/^-+|-+$/g, "")
return `${clean || session.id}.json`
}
Expand Down
Loading