MCPcopy Create free account
hub / github.com/aurora-develop/aurora / TestRobustJSONRepairsWindowsPath

Function TestRobustJSONRepairsWindowsPath

internal/toolcall/parser_test.go:191–211  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

189}
190
191func TestRobustJSONRepairsWindowsPath(t *testing.T) {
192 // Go json 接受 \f 解析为 form-feed 字符(0x0C),所以最终 path 会损失 "f" 字母
193 // —— 这是 同源行为:仅修复 *真正* 会被 Go json 拒绝的 \s 等。
194 in := `{"filePath":"G:\src\file.py","ok":true}`
195 v, ok := robustJSON(in)
196 if !ok {
197 t.Fatalf("robustJSON should produce valid json")
198 }
199 // 把对象重新 marshal 出去,确认原始 \s 已被双倍(即出现 \\s)。
200 // 不查 "含 \s":会与 "\\s" 误匹配;改用 \s 前面不是 \ 的模式。
201 str, _ := json.Marshal(v)
202 s := string(str)
203 for i := 0; i < len(s)-1; i++ {
204 if s[i] == '\\' && s[i+1] == 's' {
205 if i > 0 && s[i-1] == '\\' {
206 continue // \s 已被修正为 \\s,这是正确结果
207 }
208 t.Fatalf("found lone \\s at offset %d: %s", i, s)
209 }
210 }
211}
212
213func TestRobustJSONTruncatesUnbalanced(t *testing.T) {
214 in := `{"a": 1, "b": "unterminated` // 没有 } 和 "

Callers

nothing calls this directly

Calls 1

robustJSONFunction · 0.85

Tested by

no test coverage detected