From d581f5be0d82fe947a8a92fee409199ffff18cc2 Mon Sep 17 00:00:00 2001 From: Arinjay Wyawhare <72088094+jaywyawhare@users.noreply.github.com> Date: Thu, 26 Nov 2026 07:53:36 +0530 Subject: [PATCH] Strip leading and trailing dots from Obsidian note names --- src/selfgraph/_export.py | 4 +++- tests/test_trust.py | 8 ++++++++ typescript/src/export.ts | 5 ++++- typescript/test/conformance/py_side.py | 4 ++++ typescript/test/conformance/ts_side.ts | 4 ++++ typescript/test/trust.test.ts | 5 +++++ 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/selfgraph/_export.py b/src/selfgraph/_export.py index e6838068..a30cff57 100644 --- a/src/selfgraph/_export.py +++ b/src/selfgraph/_export.py @@ -140,7 +140,9 @@ def _stem(text: str) -> str: @param text (str): the name. @return (str): the file name without extension, or "" when nothing usable is left. """ - stem = _UNSAFE.sub("-", text).strip().strip(".").strip() + stem = _UNSAFE.sub("-", text) + while (trimmed := stem.strip().strip(".")) != stem: + stem = trimmed raw = stem.encode("utf-8") if len(raw) <= _STEM_MAX_BYTES: return stem diff --git a/tests/test_trust.py b/tests/test_trust.py index 1ccdbc31..0c83aa12 100644 --- a/tests/test_trust.py +++ b/tests/test_trust.py @@ -427,6 +427,14 @@ def test_obsidian_vault_cuts_long_names_without_splitting_a_character(): assert "\u00e9" * 100 + ".md" in notes +def test_obsidian_vault_strips_leading_and_trailing_dots(): + names = [". .NET", "Acme. .", "v1. ."] + g = fresh_graph("vault_dots") + run(g.insert.facts({"entities": [{"type": "Product", "name": name} for name in names]})) + notes = sorted(path for path in run(g.export_obsidian()) if "/" not in path) + assert notes == ["Acme.md", "NET.md", "v1.md"] + + def test_obsidian_vault_numbers_names_that_collide_after_the_cut(): g = fresh_graph("vault_clash") prefix = "z" * 300 diff --git a/typescript/src/export.ts b/typescript/src/export.ts index 149b240a..5cb3212a 100644 --- a/typescript/src/export.ts +++ b/typescript/src/export.ts @@ -142,7 +142,10 @@ export function toOssie(raw: Schema | ParsedSchema): Obj { * @return (string): the file name without extension, or "" when nothing usable is left. */ function stem(text: string): string { - const cleaned = pyStrip(pyStrip(pyStrip(text.replace(UNSAFE, "-")), ".")); + let cleaned = text.replace(UNSAFE, "-"); + for (let trimmed = pyStrip(pyStrip(cleaned), "."); trimmed !== cleaned; trimmed = pyStrip(pyStrip(cleaned), ".")) { + cleaned = trimmed; + } const raw = utf8(cleaned); if (raw.length <= STEM_MAX_BYTES) return cleaned; let end = STEM_MAX_BYTES; diff --git a/typescript/test/conformance/py_side.py b/typescript/test/conformance/py_side.py index 7407cff3..f0924c82 100644 --- a/typescript/test/conformance/py_side.py +++ b/typescript/test/conformance/py_side.py @@ -2959,6 +2959,10 @@ async def vault_names(graph): "\u5317" * 150, "z" * 210 + "a", "z" * 210 + "b", + ". .NET", + "Acme. .", + "v1. .", + "D" * 199 + ". .", ] for name in names: await g.entities.create(name, "Thing") diff --git a/typescript/test/conformance/ts_side.ts b/typescript/test/conformance/ts_side.ts index ca86e468..10473b20 100644 --- a/typescript/test/conformance/ts_side.ts +++ b/typescript/test/conformance/ts_side.ts @@ -2922,6 +2922,10 @@ async function vaultNames(graph: SelfGraph): Promise { "\u5317".repeat(150), `${"z".repeat(210)}a`, `${"z".repeat(210)}b`, + ". .NET", + "Acme. .", + "v1. .", + `${"D".repeat(199)}. .`, ]; for (const name of names) await g.entities.create(name, "Thing"); return Object.keys(await g.exportObsidian()).sort(comparePy); diff --git a/typescript/test/trust.test.ts b/typescript/test/trust.test.ts index 4e82b7ab..d6a00f6a 100644 --- a/typescript/test/trust.test.ts +++ b/typescript/test/trust.test.ts @@ -828,6 +828,11 @@ describe("obsidian vault file names", () => { ), ).filter((path) => !path.includes("/")); + it("strips leading and trailing dots from note names", () => { + const out = notes([". .NET", "Acme. .", "v1. ."]).sort(); + expect(out).toEqual(["Acme.md", "NET.md", "v1.md"]); + }); + it("cuts long names without splitting a character", () => { const out = notes([ "B".repeat(300),