From 6394f746caebb5cc219bd3a3ac908c60965df67b Mon Sep 17 00:00:00 2001 From: Wulynk Date: Wed, 24 Dec 2025 19:05:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=A4=A7=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=9A=84=E5=93=8D=E5=BA=94=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E5=8C=85=E5=90=AB=E5=8C=85=E5=90=AB=E5=A4=9A=E4=B8=AA=E5=8F=8C?= =?UTF-8?q?=E5=BC=95=E5=8F=B7=E6=97=B6=EF=BC=8C=E6=97=A0=E6=B3=95=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E6=88=90=E6=A0=91=E5=9E=8B=E7=9A=84=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phone_agent/actions/handler.py | 3 ++- phone_agent/utils/regex_util.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 phone_agent/utils/regex_util.py diff --git a/phone_agent/actions/handler.py b/phone_agent/actions/handler.py index 0bef1c3a..20a6e6d8 100644 --- a/phone_agent/actions/handler.py +++ b/phone_agent/actions/handler.py @@ -9,6 +9,7 @@ from phone_agent.config.timing import TIMING_CONFIG from phone_agent.device_factory import get_device_factory +from phone_agent.utils import regex_util @dataclass @@ -358,7 +359,7 @@ def parse_action(response: str) -> dict[str, Any]: response = response.replace('\n', '\\n') response = response.replace('\r', '\\r') response = response.replace('\t', '\\t') - + response = regex_util.escape_inner_quotes(response) tree = ast.parse(response, mode="eval") if not isinstance(tree.body, ast.Call): raise ValueError("Expected a function call") diff --git a/phone_agent/utils/regex_util.py b/phone_agent/utils/regex_util.py new file mode 100644 index 00000000..59850cc5 --- /dev/null +++ b/phone_agent/utils/regex_util.py @@ -0,0 +1,21 @@ +import re + +def escape_inner_quotes(expr: str) -> str: + """ + 解析指令字符串,转义 value 内部嵌套的、未转义的双引号。 + 使用正向断言确保只匹配真正的结构化引号。 + """ + def repl(match): + key = match.group(1) + val = match.group(2) + # 核心修复:把 value 内部「前面没有斜杠」的双引号加上斜杠 + # 比如:把 [输入了""] 变成 [输入了\"\"] + fixed_val = re.sub(r'(?