tidwall / gjson

Get JSON values quickly - JSON parser for Go
MIT License
13.88k stars 841 forks source link

Encode \b and \f in JSON string as themselves #348

Closed V02460 closed 4 months ago

V02460 commented 4 months ago

This PR fixes a test failure by adapting AppendJSONString to follow the new behavior of encoding/json in Go 1.22. The corresponding test case is appended by a check of the \b and \f characters.

Since Go 1.22 the encoding/json library encodes the characters \b and \f as themselves. Before 1.22 they were encoded as \u0008 and \u000c. The new behavior fails TestJSONString:

--- FAIL: TestJSONString (0.00s)
    gjson_test.go:2560: "1&$'\f\x16\xfa\xbah\xc9zz\x89DR\xf3"
                "1\u0026$'\u000c\u0016\ufffd\ufffdh\ufffdzz\ufffdDR\ufffd"
                "1\u0026$'\f\u0016\ufffd\ufffdh\ufffdzz\ufffdDR\ufffd"
                <<< MISMATCH >>>

Go 1.22 release notes: https://tip.golang.org/doc/go1.22#minor_library_changes

tidwall commented 4 months ago

Merged. I had to modify your test to exclude older Go versions ... in case 1.21 users want to pass the tests. https://github.com/tidwall/gjson/blob/v1.17.1/gjson_test.go#L2582

tidwall commented 4 months ago

and thanks for the PR :)