mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 13:00:52 +08:00
Fixed: #534
fix(aistudio): correct JSON string boundary detection for backslash sequences
This commit is contained in:
@@ -384,8 +384,16 @@ func ensureColonSpacedJSON(payload []byte) []byte {
|
|||||||
|
|
||||||
for i := 0; i < len(indented); i++ {
|
for i := 0; i < len(indented); i++ {
|
||||||
ch := indented[i]
|
ch := indented[i]
|
||||||
if ch == '"' && (i == 0 || indented[i-1] != '\\') {
|
if ch == '"' {
|
||||||
inString = !inString
|
// 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 {
|
if !inString {
|
||||||
|
|||||||
Reference in New Issue
Block a user