Skip to content

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

Open
aloneangel45 wants to merge 6 commits into
C4illin:mainfrom
aloneangel45:fix/697-umlaut-filename-normalization
Open

aloneangel45 wants to merge 6 commits into
C4illin:mainfrom
aloneangel45:fix/697-umlaut-filename-normalization

Conversation

@aloneangel45

@aloneangel45 aloneangel45 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

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.

Written for commit 7315bdd. Summary will update on new commits.

View guided diff

@github-actions github-actions Bot added the Fix label Nov 23, 2026
@aloneangel45
aloneangel45 force-pushed the fix/697-umlaut-filename-normalization branch from 65451c0 to 9a18358 Compare November 23, 2026 01:02

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread src/helpers/sanitizeFileName.ts Resolved
Comment thread src/pages/convert.tsx Resolved
Comment thread src/pages/download.tsx Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread src/helpers/sanitizeFileName.ts Resolved
Comment thread src/helpers/sanitizeFileName.ts Resolved
Comment thread src/helpers/sanitizeFileName.ts Resolved
Comment thread src/helpers/sanitizeFileName.ts Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 11 files

Requires human review: Auto-approval blocked because this review re-detected 4 unresolved issues already reported by Cubic.

View guided diff | Re-trigger cubic

Comment thread src/pages/upload.tsx Resolved
@aloneangel45

Copy link
Copy Markdown
Contributor Author

Addressed all @cubic-dev-ai review findings in commit 8c780fb30aa47be602e4b9a8edeec3a5232b35cd:

  1. Normalize before 255-byte truncation (src/helpers/sanitizeFileName.ts): sanitizeFileName now runs fileName.normalize("NFC") before sanitize(...) so decomposed and precomposed spellings share the exact truncation boundary.
  2. Exact-match precedence (resolveStoredFileNames): Checks the raw pre-normalized sanitized name via async access first before falling back to NFC, preserving exact resolution when both NFC and NFD files coexist.
  3. Async single-scan batch resolution (resolveStoredFileNames / resolveStoredFileName): Converted helpers to async fs/promises APIs (access + single readdir per batch in convert.tsx and async lookup in download.tsx and deleteFile.tsx).
  4. Propagate non-ENOENT/ENOTDIR filesystem errors: resolveStoredFileNames and saveUploadedFile only catch ENOENT/ENOTDIR and rethrow unexpected permission or I/O errors.
  5. Clean replacement on re-upload (src/pages/upload.tsx): Extracted saveUploadedFile to unlink any equivalent NFD on-disk entry when saving the canonical NFC filename.
  6. Tests & verification: Added tests/helpers/sanitizeFileName.test.ts (4 tests passing) and re-upload replacement test in tests/pages/upload.test.ts; bun run lint:tsc (0 errors across 59 files), bun run lint:knip, bun run lint:xss, prettier --check on touched files, eslint, and 91 tests across 11 helper/page test files passed (only pre-existing Windows teardown EBUSY in tests/preload.ts:47).

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Addressed all @cubic-dev-ai review findings in commit 8c780fb30aa47be602e4b9a8edeec3a5232b35cd:

  1. Normalize before 255-byte truncation (src/helpers/sanitizeFileName.ts): sanitizeFileName now runs fileName.normalize("NFC") before sanitize(...) so decomposed and precomposed spellings share the exact truncation boundary.
  2. Exact-match precedence (resolveStoredFileNames): Checks the raw pre-normalized sanitized name via async access first before falling back to NFC, preserving exact resolution when both NFC and NFD files coexist.
  3. Async single-scan batch resolution (resolveStoredFileNames / resolveStoredFileName): Converted helpers to async fs/promises APIs (access + single readdir per batch in convert.tsx and async lookup in download.tsx and deleteFile.tsx).
  4. Propagate non-ENOENT/ENOTDIR filesystem errors: resolveStoredFileNames and saveUploadedFile only catch ENOENT/ENOTDIR and rethrow unexpected permission or I/O errors.
    ...

@aloneangel45 The fixes close out all the original findings — I re-checked the current diff and nothing from the previous review is still open.

  • NFC before truncation: sanitizeFileName normalizes before sanitize(...), so both forms hit the same 255-byte boundary; the new unit test covers it.
  • Exact-match precedence: the access probe on the raw sanitized name runs before the NFC fallback, and the single readdir is only used for stragglers. The coexistence test is correctly skipped on macOS where NFC/NFD are the same file.
  • Async batch resolution: one readdir per batch in convert.tsx, async lookups in download/delete, and only ENOENT/ENOTDIR are swallowed — permission/I/O errors propagate.
  • Re-upload replacement: saveUploadedFile unlinks the equivalent NFD entry before writing NFC, and the test confirms the old content is gone.

Two optional nits, nothing blocking:

  • resolveStoredFileName's ?? sanitizeFileName(fileName) fallback is unreachable — resolveStoredFileNames always fills index 0. Harmless to keep.
  • In saveUploadedFile, if an NFC and NFD entry somehow both exist on disk, re-upload removes only the NFD one and overwrites NFC; the NFC copy wins, so behavior stays correct.

The convert/delete/download paths all resolve through the same helper, and handleConvert's output filtering normalizes both sides of the comparison, so the normalization story is consistent end to end.

Tip: get faster answers by chatting with cubic’s review copilot in the review UI

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 7 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread src/pages/upload.tsx Resolved
Comment thread tests/helpers/sanitizeFileName.test.ts Resolved
@aloneangel45

Copy link
Copy Markdown
Contributor Author

Addressed both follow-up points from the latest review in commit 7315bdd:

  • src/pages/upload.tsx: switched multipart uploads to saveUploadedFiles, resolving the entire batch via a single resolveStoredFileNames directory scan instead of rescanning per file.
  • tests/helpers/sanitizeFileName.test.ts: skipped the NFD/NFC batch spelling assertion on darwin where case/normalization-insensitive APFS resolves access(NFC) to the existing NFD entry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Files with German Umlauts fail

1 participant