mirror of
https://github.com/golang/go.git
synced 2026-06-27 19:30:52 +00:00
cmd/dist: fix JSON processing of trailing bytes
The testJSONFilter.process was implicitly depending on the exact internal buffer size of the json.Decoder, which happened to be large enough in v1 for most lines that cmd/dist cared about. However, the re-implementation of v1 using encoding/json/v2 changes the implicit buffer size used, which results in some trailing bytes accidentally being discarded. The correct use of json.Decoder.Buffered requires also consulting the input io.Reader for additional trailing data. Fixes #79498 Change-Id: If4bdac12b638d78e0870808f2285fb1731b0fae6 Reviewed-on: https://go-review.googlesource.com/c/go/+/779980 Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Damien Neil <dneil@google.com> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
5563d58a15
commit
0db7bea636
1 changed files with 3 additions and 1 deletions
4
src/cmd/dist/testjson.go
vendored
4
src/cmd/dist/testjson.go
vendored
|
|
@ -80,7 +80,8 @@ func (f *testJSONFilter) process(line []byte) {
|
|||
// struct, or other additions outside of it. If humans are ever looking
|
||||
// at the output, it's really nice to keep field order because it
|
||||
// preserves a lot of regularity in the output.
|
||||
dec := json.NewDecoder(bytes.NewBuffer(line))
|
||||
lineBuf := bytes.NewBuffer(line)
|
||||
dec := json.NewDecoder(lineBuf)
|
||||
dec.UseNumber()
|
||||
val, err := decodeJSONValue(dec)
|
||||
if err == nil && val.atom == json.Delim('{') {
|
||||
|
|
@ -105,6 +106,7 @@ func (f *testJSONFilter) process(line []byte) {
|
|||
// Copy any trailing text. We expect at most a "\n" here, but
|
||||
// there could be other text and we want to feed that through.
|
||||
io.Copy(f.w, dec.Buffered())
|
||||
io.Copy(f.w, lineBuf)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue