From 1239f5afc8699f607a8e50ca90516041477fd5dc Mon Sep 17 00:00:00 2001 From: TeslaZY Date: Wed, 28 May 2025 19:16:31 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20bad=20escape=20\P=20at=20position=20374?= =?UTF-8?q?=20(line=2018,=20column=2023)=20when=20using=20th=E2=80=A6=20(#?= =?UTF-8?q?7909)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …e graph feature (#1727) ### What problem does this PR solve? ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- agent/component/template.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/agent/component/template.py b/agent/component/template.py index 1b450a251..b49c51594 100644 --- a/agent/component/template.py +++ b/agent/component/template.py @@ -119,7 +119,10 @@ class Template(ComponentBase): v = json.dumps(v, ensure_ascii=False) except Exception: pass - content = re.sub(r"\{%s\}" % re.escape(n), v, content) + # Process backslashes in strings, Use Lambda function to avoid escape issues + if isinstance(v, str): + v = v.replace("\\", "\\\\") + content = re.sub(r"\{%s\}" % re.escape(n), lambda match: v, content) content = re.sub(r"(#+)", r" \1 ", content) return Template.be_output(content)