]> Cypherpunks repositories - gostls13.git/commit
encoding/json: fix Indent trailing whitespace regression in goexperiment.jsonv2
authorJoe Tsai <joetsai@digital-static.net>
Thu, 31 Jul 2025 23:21:41 +0000 (16:21 -0700)
committerGopher Robot <gobot@golang.org>
Mon, 11 Aug 2025 19:17:50 +0000 (12:17 -0700)
commit691af6ca28dad9c72e51346fe10c6aaadc3f940b
treea8ff08ab831d7baf77bea9c12df6a273d142333e
parent925149da2009589f6f2567564e1c7370e9f93b1b
encoding/json: fix Indent trailing whitespace regression in goexperiment.jsonv2

The Indent function preserves trailing whitespace,
while the v1 emulation under v2 implementation accidentally dropped it.

There was prior logic that attempted to preserve it,
but it did not work correctly since it ran in a defer and
accidentally mutated the dst input argument rather than the output argument.
Move the logic to the end and avoid a defer.
Also, add a test to both v1 and v1in2 to codify this behavior.

This only modifies code that is compiled in under goexperiment.jsonv2.

Updates #13520
Fixes #74806

Change-Id: I22b1a8da5185eb969e2a8a111b625d3752cfcbe8
Reviewed-on: https://go-review.googlesource.com/c/go/+/692195
Reviewed-by: Sean Liao <sean@liao.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Sean Liao <sean@liao.dev>
src/encoding/json/scanner_test.go
src/encoding/json/v2_indent.go
src/encoding/json/v2_scanner_test.go