Skip to content

A self-organizing Obsidian vault that gives AI coding agents persistent memory.

fix: a YAML-escaped apostrophe in an alias never matched its link (#206)

HoangThai1866acd9ba1c3d
diff --git a/.claude/scripts/lib/wikilinks.ts b/.claude/scripts/lib/wikilinks.ts
index 915d3e1..4294c5b 100644
--- a/.claude/scripts/lib/wikilinks.ts
+++ b/.claude/scripts/lib/wikilinks.ts
@@ -116,13 +116,22 @@ export function extractAliases(content: string): string[] {
const idx = lines.findIndex((l) => /^aliases:\s*(\[.*\])?\s*$/.test(l.trim()) || /^aliases:\s*\[/.test(l.trim()));
if (idx === -1) return [];
const head = lines[idx]?.trim() ?? "";
+ // Undo the quoting rather than merely removing the quote marks — the two
+ // differ on exactly the values that need it. A YAML single-quoted scalar
+ // escapes an apostrophe by DOUBLING it, so `'the writer''s two facts'`
+ // stripped charwise yields an alias no link can ever cite. Any writer
+ // emitting YAML quotes a value containing an apostrophe, and aliases are
+ // commonly the note's own title, so this is a steady fraction of generated
+ // notes rather than an edge case — and against a zero gate one false
+ // positive turns the whole check red. The two quote styles are separated
+ // because only the single-quoted form uses `''`; double-quoted content is
+ // passed through, which is what the gate's callers already expect.
const unquote = (s: string): string => {
const t = s.trim();
- if (
- (t.startsWith('"') && t.endsWith('"')) ||
- (t.startsWith("'") && t.endsWith("'"))
- ) {
- return t.slice(1, -1);
+ if (t.length < 2) return t; // a lone `'` starts and ends with itself
+ if (t.startsWith('"') && t.endsWith('"')) return t.slice(1, -1);
+ if (t.startsWith("'") && t.endsWith("'")) {
+ return t.slice(1, -1).replaceAll("''", "'");
}
return t;
};
diff --git a/.claude/scripts/tests/wikilinks.test.ts b/.claude/scripts/tests/wikilinks.test.ts
index e16f041..e244f66 100644
--- a/.claude/scripts/tests/wikilinks.test.ts
+++ b/.claude/scripts/tests/wikilinks.test.ts
@@ -115,6 +115,22 @@ describe("extractAliases", () => {
const md = "---\naliases:\n - One\ntags:\n - brain\n---\n";
assert.deepEqual(extractAliases(md), ["One"]);
});
+ test("single-quoted alias unescapes YAML's doubled apostrophe", () => {
+ const md = "---\naliases:\n - 'the writer''s two facts'\n---\n";
+ assert.deepEqual(extractAliases(md), ["the writer's two facts"]);
+ });
+ test("inline array form unescapes it too", () => {
+ const md = "---\naliases: ['Sarah''s 1:1', Plain]\n---\n";
+ assert.deepEqual(extractAliases(md), ["Sarah's 1:1", "Plain"]);
+ });
+ test("double-quoted alias keeps a bare apostrophe unchanged", () => {
+ const md = "---\naliases:\n - \"the writer's two facts\"\n---\n";
+ assert.deepEqual(extractAliases(md), ["the writer's two facts"]);
+ });
+ test("a lone apostrophe is not a quote pair", () => {
+ const md = "---\naliases:\n - '\n---\n";
+ assert.deepEqual(extractAliases(md), ["'"]);
+ });
});
describe("buildResolver", () => {