From 71576ff1289f9b5596496e52076a8ae9a4465f72 Mon Sep 17 00:00:00 2001 From: Liyuk Date: Tue, 18 Aug 2026 05:49:54 -0700 Subject: [PATCH] fix: escape {{template variables}} in assemble to prevent DSH prompt interpolation errors Node content may contain {{unsubscribe_url}} or similar template syntax (e.g. from Buttondown email templates). DSH's prompt template system scans injected contexts for {{variable}} patterns and throws when encountering unregistered ones. Escape {{ and }} as HTML entities in escapeXml so they pass through DSH's interpolation untouched. Only paired braces are escaped; single { or } are preserved for CSS/JSON compatibility. --- src/format/assemble.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/format/assemble.ts b/src/format/assemble.ts index 8d0aa78..d7ad1c1 100755 --- a/src/format/assemble.ts +++ b/src/format/assemble.ts @@ -204,5 +204,13 @@ export function assembleContext( } function escapeXml(s: string): string { - return s.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """); -} \ No newline at end of file + return s + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + // 防止 DSH prompt template 系统把 {{variable}} 当成需要解析的变量 + // 只转义成对的 {{ }},保留单个 { } 不动(兼容 CSS/JSON 等内容) + .replace(/\{\{/g, "{{") + .replace(/\}\}/g, "}}"); +}