Skip to content

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

Merged
tidwall merged 2 commits intotidwall:masterfrom
V02460:json_string
Feb 15, 2024
Merged

Encode \b and \f in JSON string as themselves#348
tidwall merged 2 commits intotidwall:masterfrom
V02460:json_string

Conversation

@V02460
Copy link
Contributor

@V02460 V02460 commented Feb 14, 2024

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 tidwall merged commit 711c6fe into tidwall:master Feb 15, 2024
@tidwall
Copy link
Owner

tidwall commented Feb 15, 2024

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
Copy link
Owner

tidwall commented Feb 15, 2024

and thanks for the PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants