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
17 changes: 17 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,23 @@ describe("sessionExportFilename", () => {
test("falls back to id when title and slug are empty", () => {
expect(sessionExportFilename({ id: "ses_123" })).toBe("ses_123.json")
})

test("avoids Windows reserved device names", () => {
const reserved = [
"CON",
"PRN",
"AUX",
"NUL",
...Array.from({ length: 9 }, (_, index) => `COM${index + 1}`),
...Array.from({ length: 9 }, (_, index) => `LPT${index + 1}`),
]

reserved.forEach((title) =>
expect(sessionExportFilename({ id: "ses_123", title })).toBe(`${title.toLowerCase()}-session.json`),
)
expect(sessionExportFilename({ id: "ses_123", title: "COM0" })).toBe("com0.json")
expect(sessionExportFilename({ id: "ses_123", title: "COM10" })).toBe("com10.json")
})
})

describe("fetchSessionExport", () => {
Expand Down
5 changes: 4 additions & 1 deletion 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 WINDOWS_RESERVED_NAME = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i

export async function fetchSessionExport(input: {
sessionID: string
client: SessionExportClient
Expand Down Expand Up @@ -44,7 +46,8 @@ export function sessionExportFilename(session: { id: string; title?: string; slu
.toLowerCase()
.replace(/[^a-z0-9_-]+/gi, "-")
.replace(/^-+|-+$/g, "")
return `${clean || session.id}.json`
const basename = clean || session.id
return `${WINDOWS_RESERVED_NAME.test(basename) ? `${basename}-session` : basename}.json`
}

export function downloadSessionExport(filename: string, data: unknown) {
Expand Down
Loading