(t *testing.T)
| 189 | } |
| 190 | |
| 191 | func 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 | |
| 213 | func TestRobustJSONTruncatesUnbalanced(t *testing.T) { |
| 214 | in := `{"a": 1, "b": "unterminated` // 没有 } 和 " |
nothing calls this directly
no test coverage detected