A self-organizing Obsidian vault that gives AI coding agents persistent memory.
TypeScript ai-agentsclaude-codecodex-cligemini-cliknowledge-managementobsidianobsidian-vaultpersistent-memorysecond-braintemplate
fix: a double-quoted alias with an escaped quote never matched its link (#218)
Brenno Ferraridbcead7a6cc2
diff --git a/.claude/scripts/lib/wikilinks.ts b/.claude/scripts/lib/wikilinks.tsindex 19e22b6..091c690 100644--- a/.claude/scripts/lib/wikilinks.ts+++ b/.claude/scripts/lib/wikilinks.ts@@ -181,13 +181,29 @@ export function extractAliases(content: string): string[] {// 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.+ // positive turns the whole check red.+ //+ // The two styles need SEPARATE rules because they escape differently, not+ // because only one escapes: single-quoted doubles the apostrophe, and+ // double-quoted uses a backslash. Passing the double-quoted form through+ // charwise left `"the \"good\" parts"` as an alias carrying literal+ // backslashes, which is the same defect the single-quoted branch was fixed+ // for and reaches the gate the same way.+ //+ // Only `\\` and `\"` are undone. YAML's double-quoted form also defines+ // `\n`, `\t`, `\/` and `\uXXXX`, which do not occur in a note title at any+ // rate worth carrying a decoder for; each one added is a rule that has to+ // stay correct forever. This matches `unquoteScalar` in+ // `lib/mcp-memory-bridge.ts`, which is the copy that already reasons about+ // escaping, so the two agree rather than drifting.const unquote = (s: string): string => {const t = s.trim();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('"')) {+ // Left to right, so `\\"` yields a backslash and then ends the scalar+ // rather than treating the escaped backslash's quote as escaped.+ return t.slice(1, -1).replace(/\\(["\\])/g, "$1");+ }if (t.startsWith("'") && t.endsWith("'")) {return t.slice(1, -1).replaceAll("''", "'");}diff --git a/.claude/scripts/tests/wikilinks.test.ts b/.claude/scripts/tests/wikilinks.test.tsindex c60f5de..4478917 100644--- a/.claude/scripts/tests/wikilinks.test.ts+++ b/.claude/scripts/tests/wikilinks.test.ts@@ -131,6 +131,28 @@ describe("extractAliases", () => {const md = "---\naliases:\n - '\n---\n";assert.deepEqual(extractAliases(md), ["'"]);});++ // The other half of the same defect: single-quoted YAML escapes by doubling,+ // double-quoted escapes with a backslash, and stripping either charwise+ // yields a name no wikilink can cite.+ test("double-quoted alias unescapes a backslash-escaped quote", () => {+ const md = '---\naliases:\n - "the \\"good\\" parts"\n---\n';+ assert.deepEqual(extractAliases(md), ['the "good" parts']);+ });+ test("inline array form unescapes the backslash form too", () => {+ const md = '---\naliases: ["a \\"quoted\\" name", Plain]\n---\n';+ assert.deepEqual(extractAliases(md), ['a "quoted" name', "Plain"]);+ });+ test("an escaped backslash survives as one backslash", () => {+ const md = '---\naliases:\n - "a \\\\ b"\n---\n';+ assert.deepEqual(extractAliases(md), ["a \\ b"]);+ });+ // Regression guard on the branch being edited rather than a demonstration of+ // the bug: this passed before and must keep passing.+ test("a double-quoted alias with no escapes is unchanged", () => {+ const md = "---\naliases:\n - \"the writer's two facts\"\n---\n";+ assert.deepEqual(extractAliases(md), ["the writer's two facts"]);+ });});describe("buildResolver", () => {