fix(export): never emit punctuation-only Obsidian filenames (e.g. @.md)

An all-punctuation node label (e.g. `@/*` from a tsconfig paths entry) survived
the unsafe-char strip in `to_obsidian`'s `safe_name()` as a bare `@`, producing
`@.md`. That filename is valid on disk but empty once a downstream tool re-slugs
on word chars — qmd's handelize() reduces "@" -> "" and raises, aborting the
entire `qmd update` (every collection on the machine stops reindexing).

Require at least one word char in the stem; otherwise fall back to "unnamed"
(the existing dedup handles collisions). Applied to both safe_name occurrences.

Fixes #1409

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Luca Zanotti
2026-06-22 23:10:49 +01:00
committed by safishamsi
co-authored by Claude Opus 4.8
parent 0b96b61609
commit 30cc4c0670
+16 -2
View File
@@ -866,7 +866,14 @@ def to_obsidian(
cleaned = re.sub(r'[\\/*?:"<>|#^[\]]', "", label.replace("\r\n", " ").replace("\r", " ").replace("\n", " ")).strip()
# Strip trailing .md/.mdx/.markdown so "CLAUDE.md" doesn't become "CLAUDE.md.md"
cleaned = re.sub(r"\.(md|mdx|qmd|markdown)$", "", cleaned, flags=re.IGNORECASE)
return _cap_filename(cleaned) if cleaned else "unnamed"
# A stem of only punctuation (e.g. "@", "*", "#") survives the unsafe-char
# strip above but is empty once a downstream tool re-slugs on word chars
# (e.g. qmd's handelize() reduces "@" -> "" and raises, aborting the whole
# `qmd update`). Require at least one word char; else fall back so we never
# emit a "@.md"-style filename. (#1409)
if not re.search(r"\w", cleaned, flags=re.UNICODE):
return "unnamed"
return _cap_filename(cleaned)
node_filename: dict[str, str] = {}
seen_names: dict[str, int] = {}
@@ -1112,7 +1119,14 @@ def to_canvas(
def safe_name(label: str) -> str:
cleaned = re.sub(r'[\\/*?:"<>|#^[\]]', "", label.replace("\r\n", " ").replace("\r", " ").replace("\n", " ")).strip()
cleaned = re.sub(r"\.(md|mdx|qmd|markdown)$", "", cleaned, flags=re.IGNORECASE)
return _cap_filename(cleaned) if cleaned else "unnamed"
# A stem of only punctuation (e.g. "@", "*", "#") survives the unsafe-char
# strip above but is empty once a downstream tool re-slugs on word chars
# (e.g. qmd's handelize() reduces "@" -> "" and raises, aborting the whole
# `qmd update`). Require at least one word char; else fall back so we never
# emit a "@.md"-style filename. (#1409)
if not re.search(r"\w", cleaned, flags=re.UNICODE):
return "unnamed"
return _cap_filename(cleaned)
# Build node_filenames if not provided (same dedup logic as to_obsidian)
if node_filenames is None: