Fix: bad escape \P at position 374 (line 18, column 23) when using th… (#7909)

…e graph feature (#1727)

### What problem does this PR solve?

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
TeslaZY 2025-05-28 19:16:31 +08:00 committed by GitHub
parent 243ed4bc35
commit 1239f5afc8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -119,7 +119,10 @@ class Template(ComponentBase):
v = json.dumps(v, ensure_ascii=False) v = json.dumps(v, ensure_ascii=False)
except Exception: except Exception:
pass 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) content = re.sub(r"(#+)", r" \1 ", content)
return Template.be_output(content) return Template.be_output(content)