From 30cc4c067010f094793237636a602d347c6016a4 Mon Sep 17 00:00:00 2001 From: Luca Zanotti Date: Sat, 20 Jun 2026 21:58:57 +0200 Subject: [PATCH] fix(export): never emit punctuation-only Obsidian filenames (e.g. @.md) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- graphify/export.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/graphify/export.py b/graphify/export.py index 86ad6a9..17798d6 100644 --- a/graphify/export.py +++ b/graphify/export.py @@ -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: