Skip to content

Suggest file names Windows accepts on every platform [patch] - #203

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/171-portable-suggested-names
Oct 9, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/171-portable-suggested-names

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #171

What was wrong

Scan.SanitizeFileName replaced only Path.GetInvalidFileNameChars(). On Linux and macOS that set is just \0 and /, so "sunset at 5:30pm? <draft>" was stored unchanged. A name like that can't be used to rename a file on Windows, NTFS, SMB or exFAT, and a JSON export taken from Linux makes Import on Windows abort when FileName rejects it.

Change

  • Sanitise against a fixed set instead: < > : " / \ | ? * and control characters 0–31, each replaced with - as before. The result is the same on every OS.
  • If the cleaned stem is a Windows device name (CON, PRN, AUX, NUL, COM1–9, LPT1–9, case-insensitive), it gets an -image suffix, so con becomes con-image.jpg rather than con.jpg. A name that only starts with one, such as console-on-desk, is left alone.

Not in this PR: names already stored in existing databases are not re-sanitised, and ImportJson still aborts on a bad entry instead of skipping it per row. The triage comment lists both as separate follow-ups.

Tests

  • New tests in ScanTests: the issue's example; every reserved character plus a tab and \u0001; four device names; and a name that only starts with a device name.
  • With the fix temporarily reverted, 6 of the new test cases fail on Linux. With the fix in place, the full suite passes: 94 passed, 1 skipped.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NwJrDAUtukhDgLo9pAfR3t


Generated by Claude Code

SanitizeFileName replaced only Path.GetInvalidFileNameChars(), which is
just "\0" and "/" on Linux and macOS, so a name suggested there kept
: ? * < > | \ " and could not be used to rename on Windows, NTFS, SMB or
exFAT, and made a JSON import on Windows abort. Replace a fixed,
platform-independent set (those characters plus control characters)
with "-", and suffix a Windows device name such as "con" so it does not
become con.jpg.

Fixes #171

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NwJrDAUtukhDgLo9pAfR3t
@sonarqubecloud

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit daf701d into main Oct 9, 2026
14 checks passed
@matt-edmondson
matt-edmondson deleted the fix/171-portable-suggested-names branch October 9, 2026 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants