aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/json/v2
diff options
context:
space:
mode:
authorJoe Tsai <joetsai@digital-static.net>2025-10-11 11:37:58 -0700
committerJoseph Tsai <joetsai@digital-static.net>2025-10-13 17:01:45 -0700
commit6fd8e88d07b08531a5585aa4fbcc6043d556742f (patch)
tree228722ad58335f82fc1ae1fb548ceba7fea3d3d5 /src/encoding/json/v2
parent1abc6b0204ed231311c9bbc53cfab36dc546aa8e (diff)
downloadgo-6fd8e88d07b08531a5585aa4fbcc6043d556742f.tar.xz
encoding/json/v2: restrict presence of default options
Originally, DefaultOptionsV1 and DefaultOptionsV2 represented the full set of all options with specific ones set to true or false. However, there are certain options such as WithIndent or WithMarshalers that are neither v1 or v2 specific. At some point we removed whitespace related options from the set: https://github.com/go-json-experiment/json/pull/26 This avoids DefaultOptionsV1 or DefaultOptionsV2 from affecting any previously set whitespace. However, why are whitespace options special and thus excluded from the set? What about Marshalers? As a more principaled way to address this, we restrict DefaultOptionsV1 and DefaultOptionsV2 to only be the options where the default setting changes between v1 and v2. All other options are unpopulated. This avoids a panic with GetOption(DefaultOptionsV2, WithMarshalers) since DefaultOptionsV2 previously had the presence bit for Marshalers set to true, but had no actual value. Now, the presence bit is set to false, so the value is not consulted. Fixes #75149 Change-Id: I30b45abd35404578b4135cc3bad1a1a2993cb0cf Reviewed-on: https://go-review.googlesource.com/c/go/+/710878 Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
Diffstat (limited to 'src/encoding/json/v2')
-rw-r--r--src/encoding/json/v2/options.go5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/encoding/json/v2/options.go b/src/encoding/json/v2/options.go
index 0942d2d307..9685f20f9f 100644
--- a/src/encoding/json/v2/options.go
+++ b/src/encoding/json/v2/options.go
@@ -97,9 +97,8 @@ func GetOption[T any](opts Options, setter func(T) Options) (T, bool) {
}
// DefaultOptionsV2 is the full set of all options that define v2 semantics.
-// It is equivalent to all options under [Options], [encoding/json.Options],
-// and [encoding/json/jsontext.Options] being set to false or the zero value,
-// except for the options related to whitespace formatting.
+// It is equivalent to the set of options in [encoding/json.DefaultOptionsV1]
+// all being set to false. All other options are not present.
func DefaultOptionsV2() Options {
return &jsonopts.DefaultOptionsV2
}