Closed edwargix closed 2 years ago
gjson v1.11.0 fixed a couple bugs that are related to your specific issue.
1) In v1.10.2 and below the Parse function returned a Result where the Index field is always zero.
This was wrong. It should have been an Index that is the position of the first character of its Raw value in the original json.
2) Also in v1.10.2 and below the ForEach iterator returned values with an Index that was relative to the parent, not the original json.
This too was wrong. It should have also been an Index that is the position of the first character of its Raw value in the original json.
For example:
In v1.10.2 (wrong):
json := "\t\n[{\"key\":9007199254740991},{\"key\":9007199298273917}]"
println(Parse(json).Index)
Parse(json).ForEach(func(key, value Result) bool {
println(value.Index)
return true
})
// output:
// 0
// 1
// 26
In v1.11.0 (right):
json := "\t\n[{\"key\":9007199254740991},{\"key\":9007199298273917}]"
println(Parse(json).Index)
Parse(json).ForEach(func(key, value Result) bool {
println(value.Index)
return true
})
// output:
// 2
// 3
// 28
I hope this information is understandable.
I took the liberty to change your crypto/canonicaljson/json.go
code so that it will fix the issue on your side:
https://gist.github.com/tidwall/7549bdbf3fae285dd20620c63d4672d5
I took the liberty to change your
crypto/canonicaljson/json.go
code so that it will fix the issue on your side:https://gist.github.com/tidwall/7549bdbf3fae285dd20620c63d4672d5
Thank you much!
Hiya,
The mautrix-go library uses gjson. Some of its json tests broke on commit 2c9fd24 (aka tag v1.11.0), as can be seen under "Steps to reproduce". An issue for this was filed in mautrix-go: https://github.com/mautrix/go/issues/52
The mautrix-go function seems to be using the json slice optimization described under Working with Bytes. Perhaps this has something to do with the problem? https://github.com/mautrix/go/blob/v0.10.9/crypto/canonicaljson/json.go#L266-L280
Steps to reproduce
1. checkout mautrix-go version v0.10.9 (the latest release)
2. run the
crypto/canonicaljson
tests using gjson v1.10.2 and 7cadbb5 (the commit after v1.10.2)Notice that the tests run fine for these version of gjson:
3. re-run the same tests using gjson v1.11.0 (commit 2c9fd24, aka first commit after 7cadbb5 from step 2)
Notice that we experience a panic on this version of gjson:
4. re-run the tests with gjson v1.13.0 (the latest release)
Notice that the problem persists: