]> Cypherpunks repositories - gostls13.git/commit
encoding/json: fix Decoder.InputOffset regression in goexperiment.jsonv2
authorJoe Tsai <joetsai@digital-static.net>
Mon, 15 Sep 2025 19:56:11 +0000 (12:56 -0700)
committerJoseph Tsai <joetsai@digital-static.net>
Thu, 2 Oct 2025 06:02:56 +0000 (23:02 -0700)
commit633dd1d475e7346b43d87abc987a8c7f256e827d
treeb4e7a935dc3b0bf3c8bcf4d91baa804678bd6742
parent8ad27fb656ab162546137b512c61f6a26a90a6c5
encoding/json: fix Decoder.InputOffset regression in goexperiment.jsonv2

The Decoder.InputOffset method was always ambiguous about the exact
offset returned since anything between the end of the previous token
to the start of the next token could be a valid result.

Empirically, it seems that the behavior was to report
the end of the previous token unless Decoder.More is called,
in which case it reports the start of the next token.

This is an odd semantic since a relatively side-effect free method
like More is not quite so side-effect free.
However, our goal is to preserve historical v1 semantic when possible
regardless of whether it made sense.

Note that jsontext.Decoder.InputOffset consistently always reports
the end of the previous token. Users can explicitly choose the
exact position they want by inspecting the UnreadBuffer.

Fixes #75468

Change-Id: I1e946e83c9d29dfc09f2913ff8d6b2b80632f292
Reviewed-on: https://go-review.googlesource.com/c/go/+/703856
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
src/encoding/json/stream_test.go
src/encoding/json/v2_stream.go
src/encoding/json/v2_stream_test.go