fix: match obsidian-importer illegal character filter in slugs

This commit is contained in:
saberzero1 2026-06-03 15:10:02 +02:00
parent e09d8b0bbc
commit 37b89c3fbe
No known key found for this signature in database
2 changed files with 19 additions and 0 deletions

View file

@ -303,6 +303,7 @@ export function slugifyPath(s: string): string {
.replace(/%/g, "-percent")
.replace(/\?/g, "")
.replace(/#/g, "")
.replace(/[<>:"|*]/g, "")
.toLowerCase(),
)
.join("/")

View file

@ -287,6 +287,24 @@ describe("slugifyPath", () => {
it("lowercases for case-insensitive matching (Obsidian parity)", () => {
expect(slugifyPath("Compendium/Species/Dryad/Apple")).toBe("compendium/species/dryad/apple");
});
it('removes filesystem-illegal characters (< > : " | *)', () => {
expect(slugifyPath("Alias with <illegal> chars")).toBe("alias-with-illegal-chars");
});
it("removes colons and pipes", () => {
expect(slugifyPath("Title: Subtitle | Part")).toBe("title-subtitle--part");
});
it("removes asterisks and quotes", () => {
expect(slugifyPath('What is "AI"*')).toBe("what-is-ai");
});
it("handles mixed illegal characters across path segments", () => {
expect(slugifyPath("Guides/X-Men: First Class/Notes <draft>")).toBe(
"guides/x-men-first-class/notes-draft",
);
});
});
describe("splitAnchor", () => {