Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/selfgraph/_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions tests/test_trust.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion typescript/src/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions typescript/test/conformance/py_side.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions typescript/test/conformance/ts_side.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2922,6 +2922,10 @@ async function vaultNames(graph: SelfGraph): Promise<string[]> {
"\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);
Expand Down
5 changes: 5 additions & 0 deletions typescript/test/trust.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Loading