Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): de-duplicate zip entry names case-insensitively (R1-L1)
M9fc284aa6188
diff --git a/desktop-app/ui/src/lib/__tests__/zipWriter.test.ts b/desktop-app/ui/src/lib/__tests__/zipWriter.test.tsindex 135c01ec7..6d391f9f9 100644--- a/desktop-app/ui/src/lib/__tests__/zipWriter.test.ts+++ b/desktop-app/ui/src/lib/__tests__/zipWriter.test.ts@@ -89,6 +89,32 @@ describe('createZipWriter', () => {expect(writer.has('docs/plan (2).md')).toBe(true)})+ it('de-duplicates case-insensitive collisions so portable extractors never overwrite (R1-L1)', () => {+ const writer = createZipWriter()+ writer.addFile('Report.txt', textBytes('upper'))+ writer.addFile('report.txt', textBytes('lower'))+ writer.addFile('REPORT.TXT', textBytes('shout'))++ const entries = readStoredZip(writer.build())+ expect(entries.map(entry => entry.name)).toEqual([+ 'Report.txt',+ 'report (2).txt',+ 'REPORT (3).TXT',+ ])+ // Distinct content survives the rename, byte-identical.+ const contentDecoder = new TextDecoder()+ expect(entries.map(entry => contentDecoder.decode(entry.bytes))).toEqual([+ 'upper',+ 'lower',+ 'shout',+ ])+ expect(writer.has('report.txt')).toBe(true)+ // Case-insensitive membership: the shout-case original collides with the+ // set even though it was renamed on write.+ expect(writer.has('REPORT.TXT')).toBe(true)+ expect(writer.has('report (4).txt')).toBe(false)+ })+it('marks names as UTF-8 in both header sets', () => {const writer = createZipWriter()writer.addFile('报告/tafel-übe.png', textBytes('x'))diff --git a/desktop-app/ui/src/lib/zipWriter.ts b/desktop-app/ui/src/lib/zipWriter.tsindex 2efff0569..86a28dc43 100644--- a/desktop-app/ui/src/lib/zipWriter.ts+++ b/desktop-app/ui/src/lib/zipWriter.ts@@ -114,7 +114,8 @@ export function createZipWriter(options: CreateZipWriterOptions = {}): ZipWriterreturn {addFile(path, bytes) {const writtenPath = ensureUniqueName(path, usedNames)- usedNames.add(writtenPath)+ // The set holds case-folded keys: collisions are matched case-insensitively.+ usedNames.add(writtenPath.toLowerCase())const nameBytes = encodeName(writtenPath)const crc = crc32(bytes)const localHeaderOffset = length@@ -143,7 +144,7 @@ export function createZipWriter(options: CreateZipWriterOptions = {}): ZipWriter},has(path) {- return usedNames.has(path)+ return usedNames.has(path.toLowerCase())},entryCount() {@@ -193,9 +194,16 @@ export function createZipWriter(options: CreateZipWriterOptions = {}): ZipWriter}}-/** `a/b.txt` → `a/b (2).txt` style de-duplication for repeated zip names. */+/**+ * De-duplication for repeated zip entry names: `a/b.txt` → `a/b (2).txt`.+ * Matching is case-insensitive across the WHOLE path (`Report.txt` collides+ * with `report.txt`): portable case-insensitive extractors (macOS, Windows)+ * would otherwise silently overwrite one of the two during extraction, so the+ * second colliding name is suffixed instead (spec: name-collision policy).+ */function ensureUniqueName(path: string, usedNames: Set<string>): string {- if (!usedNames.has(path)) return path+ const fold = (candidate: string) => candidate.toLowerCase()+ if (!usedNames.has(fold(path))) return pathconst slash = path.lastIndexOf('/')const directory = slash >= 0 ? path.slice(0, slash + 1) : ''const base = slash >= 0 ? path.slice(slash + 1) : path@@ -204,7 +212,7 @@ function ensureUniqueName(path: string, usedNames: Set<string>): string {const extension = dot > 0 ? base.slice(dot) : ''let counter = 2let candidate = `${directory}${stem} (${counter})${extension}`- while (usedNames.has(candidate)) {+ while (usedNames.has(fold(candidate))) {counter += 1candidate = `${directory}${stem} (${counter})${extension}`}