From 27a5ad8ec28efab62a4e5b70ba5be484d5ead739 Mon Sep 17 00:00:00 2001 From: hkfires <10558748+hkfires@users.noreply.github.com> Date: Mon, 15 Dec 2025 09:00:14 +0800 Subject: [PATCH] Fixed: #534 fix(aistudio): correct JSON string boundary detection for backslash sequences --- internal/runtime/executor/aistudio_executor.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/runtime/executor/aistudio_executor.go b/internal/runtime/executor/aistudio_executor.go index 4558b319..221fb648 100644 --- a/internal/runtime/executor/aistudio_executor.go +++ b/internal/runtime/executor/aistudio_executor.go @@ -384,8 +384,16 @@ func ensureColonSpacedJSON(payload []byte) []byte { for i := 0; i < len(indented); i++ { ch := indented[i] - if ch == '"' && (i == 0 || indented[i-1] != '\\') { - inString = !inString + if ch == '"' { + // A quote is escaped only when preceded by an odd number of consecutive backslashes. + // For example: "\\\"" keeps the quote inside the string, but "\\\\" closes the string. + backslashes := 0 + for j := i - 1; j >= 0 && indented[j] == '\\'; j-- { + backslashes++ + } + if backslashes%2 == 0 { + inString = !inString + } } if !inString {