Skip to content

Keep fenced and dotted filename suggestions intact [patch] - #169

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/sanitize-fenced-dotted-names
Sep 28, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/sanitize-fenced-dotted-names

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #166

What changed

Scan.SanitizeFileName had two bugs:

  1. Code fences. It trimmed quotes and backticks before taking the first line. A fenced answer (```\nsunset-over-lake\n```) was left with an empty first line and became unnamed.jpg. It now takes the first line that has content and isn't a fence (``` or ```text), and trims quotes and backticks after that. A name written inline between fences on one line (```sunset```) is still read.
  2. Dots. Any dot was treated as an extension, so st.-louis-arch-at-dusk became st.jpg and sunset-at-5.30pm became sunset-at-5.jpg. It now strips only a known image extension (case-insensitive). The check uses a new ImageScanner.IsImageExtension, which ScanForImages also calls now, so there is one extension list.

Tests

Added beside the existing SanitizeFileName* tests in ScanTests.cs:

Input Expected Without the fix
```\nsunset-over-lake\n``` sunset-over-lake.jpg fails (unnamed.jpg)
```text\r\nsunset-over-lake\r\n``` sunset-over-lake.jpg fails
st.-louis-arch-at-dusk st.-louis-arch-at-dusk.jpg fails (st.jpg)
sunset-at-5.30pm sunset-at-5.30pm.jpg fails
\nsunset-over-lake\n sunset-over-lake.jpg passes (see note)
```sunset-over-lake``` sunset-over-lake.jpg passes
photo.JPEG → .png photo.png passes

Note: the issue lists "\nsunset-over-lake\n" as broken, but the old code's leading Trim() already removed those newlines, so that case worked. The test is kept as a regression guard.

Full suite: 53 passed. With Scan.cs reverted, the four tests marked "fails" above fail.

The triage comment suggests a follow-up for names already stored as unnamed.*. That is out of scope here, because a rescan skips hashes it already knows.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QtRTdtw1SbV7ugjz5wPFgc


Generated by Claude Code

SanitizeFileName trimmed backticks before taking the first line, so a
name inside a code fence left an empty first line and became
"unnamed". It also treated any dot as an extension, so
"sunset-at-5.30pm" became "sunset-at-5". Take the first line that has
content and isn't a fence, then trim, and strip only a known image
extension, reusing ImageScanner's set.

Fixes #166

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

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit d6c3c8b into main Sep 28, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the fix/sanitize-fenced-dotted-names branch September 28, 2026 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A code-fenced filename suggestion becomes "unnamed.jpg", and suggestions containing a dot are truncated ("st.-louis-arch" → "st.jpg")

2 participants