From 642fe04017b4602b99280d33e2002c9e17d592e7 Mon Sep 17 00:00:00 2001 From: Vanshaj Poonia Date: Mon, 12 Oct 2026 22:41:24 +0530 Subject: [PATCH] fix(#184): keep dollar signs in special variable values wrapInQuotes wrote the quoted line back with String.replace and a string replacement, so "$$", "$&" and similar sequences in a special variable value were read as replacement patterns. A title such as "Budget $$ report" came out as "Budget $ report", and "$&" pasted the whole original line into the value. Pass a replacer function so the quoted line is inserted as is. --- src/parser.ts | 3 ++- tests/parser.spec.ts | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/parser.ts b/src/parser.ts index 36bd554..432ba19 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -224,7 +224,8 @@ export class Parser { const splitVal = firstMatch.split(":"); const wrappedString = `${splitVal[0]}: "${splitVal.slice(1).join(":").trim()}"`; - definitionsBlock = definitionsBlock.replace(firstMatch, wrappedString); + // A replacer function stops "$" sequences in the value being read as replacement patterns + definitionsBlock = definitionsBlock.replace(firstMatch, () => wrappedString); } return definitionsBlock; diff --git a/tests/parser.spec.ts b/tests/parser.spec.ts index b7584bf..62ef174 100644 --- a/tests/parser.spec.ts +++ b/tests/parser.spec.ts @@ -436,6 +436,24 @@ describe("Template parser", () => { expect(parsedTemplate).toBeNull(); }); + test("should keep dollar signs in special variable values as written", async () => { + const template = { + id: "note-id", + title: "Some Template", + body: dedent` + --- + template_title: Budget $$ and $& report + + --- + ` + }; + + const parsedTemplate = await parser.parseTemplate(template); + + assert(parsedTemplate); + expect(parsedTemplate.title).toEqual("Budget $$ and $& report"); + }); + test("should skip empty values in tags special variable", async () => { const template = { id: "note-id",