mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-04-23 22:50:17 +08:00
Fix: Preserve quotes while handling variable substitution withTemplate component. (#6410)
###Address Problem: The original implementation used re.sub(r"(\\\"|\")", "", content) which stripped all quotes from the processed content. While this worked for simple Jinja2-rendered templates, it caused formatting issues when : -Quotes were required in the final output (e.g., JSON, Python Code strings) ###Solution: 1. Selective JSON Serialization. 2. Removed Global Quote Removal ### What problem does this PR solve? This PR addresses an issue in template processing where all quotation marks (" and \") were being removed from content, potentially corrupting string formatting in rendered outputs. **In fact, extra quotes is generated by json.dumps(v, ensure_ascii=False).** ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
parent
8eefc8b5fe
commit
d869e4d43f
@ -109,16 +109,14 @@ class Template(ComponentBase):
|
||||
pass
|
||||
|
||||
for n, v in kwargs.items():
|
||||
try:
|
||||
v = json.dumps(v, ensure_ascii=False)
|
||||
except Exception:
|
||||
pass
|
||||
if not isinstance(v, str):
|
||||
try:
|
||||
v = json.dumps(v, ensure_ascii=False)
|
||||
except Exception:
|
||||
pass
|
||||
content = re.sub(
|
||||
r"\{%s\}" % re.escape(n), v, content
|
||||
)
|
||||
content = re.sub(
|
||||
r"(\\\")", "", content
|
||||
)
|
||||
content = re.sub(
|
||||
r"(#+)", r" \1 ", content
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user