fix(pages): normalize Unicode filenames across upload, convert, delete, and download

AL
11h ago
+298-23

Fixes #697

Summary

Filenames containing German umlauts (or other characters with decomposed NFD vs precomposed NFC forms, e.g. macOS APFS ä U+0061 U+0308 vs ä U+00E4) could fail on Linux byte-exact filesystems with No such file or directory when upload, convert, delete, download, or multi-page output matching used different Unicode normalizations, or when the Debian runtime ran under the default C locale.

Changes

  • src/helpers/sanitizeFileName.ts: Added sanitizeFileName (sanitizes and normalizes to NFC) and resolveStoredFileName (fast-path existsSync with directory fallback matching entry.normalize("NFC")).
  • src/pages/upload.tsx, src/pages/convert.tsx, src/pages/deleteFile.tsx, src/pages/download.tsx: Switched raw sanitize(...) calls to sanitizeFileName (on upload writes) and resolveStoredFileName (when reading/converting/deleting/downloading stored files).
  • src/converters/main.ts: Normalized filenames when scanning multi-page output files in handleConvert while preserving the actual filename written on disk.
  • Dockerfile: Set ENV LANG=C.UTF-8 in the Debian runtime image so converters receive a UTF-8 locale.
  • tests/pages/{upload,convert,deleteFile,download}.test.ts: Added regression tests covering NFD upload normalization, cross-normalization (NFC <-> NFD) conversion, deletion, and URL-encoded download.

Verification

Observed locally on Windows (bun 1.4.5):

  • bun x prettier --check src/helpers/sanitizeFileName.ts src/pages/upload.tsx src/pages/convert.tsx src/pages/deleteFile.tsx src/pages/download.tsx src/converters/main.ts tests/pages/upload.test.ts tests/pages/convert.test.ts tests/pages/deleteFile.test.ts tests/pages/download.test.ts — passed
  • bun run lint:tsc — passed (0 type errors across 59 files)
  • bun run lint:knip — passed
  • bun run lint:xss — passed (No XSS vulnerabilities found in 59 files!)
  • bun x eslint <changed files> — passed (0 errors/warnings)
  • bun test tests/helpers/ tests/pages/auth.test.ts tests/pages/chooseConverter.test.ts tests/pages/convert.test.ts tests/pages/deleteFile.test.ts tests/pages/download.test.ts tests/pages/upload.test.ts — 86 tests passed (214 expect() calls), only the pre-existing Windows tests/preload.ts:47 EBUSY cleanup hook failed on teardown (tests/db/db.test.ts:79 also hits Windows SQLite EBUSY on unlink; tests/integration requires Docker tools and was not run).

Summary by cubic

Fixes #697 by normalizing Unicode filenames to NFC so names with umlauts (or other decomposed characters) survive upload, convert, delete, and download on Linux byte-exact filesystems.

  • New sanitizeFileName helper normalizes NFC before sanitizing; resolveStoredFileNames resolves exact or NFC-equivalent stored entries in a single async batch.
  • Upload, convert, delete, and download use these helpers; re-uploading an NFC name replaces an NFD-equivalent stored file; multi-page output matching normalizes filenames too.
  • The Docker image sets LANG=C.UTF-8 so converters run in a UTF-8 locale.
  • Adds regression tests covering NFD uploads, cross-normalization conversion and delete, and URL-encoded downloads.