aboutsummaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
authorDavid Chase <drchase@google.com>2022-03-07 18:27:14 -0500
committerDavid Chase <drchase@google.com>2022-03-07 18:27:14 -0500
commitf49279383901af656e40f225eb67ff62f507e13d (patch)
tree456dc18ec82112c48d73ef2a3f369e15dc84ed05 /src/math
parent768804dfdd81b04a1184c86e538634872b907149 (diff)
parentc9b60632ebb08a428a9bd15a89798a693667cb05 (diff)
downloadgo-f49279383901af656e40f225eb67ff62f507e13d.tar.xz
[dev.boringcrypto] all: merge master into dev.boringcrypto
Change-Id: I4e09d4f2cc77c4c2dc12f1ff40d8c36053ab7ab6
Diffstat (limited to 'src/math')
-rw-r--r--src/math/big/intmarsh.go5
-rw-r--r--src/math/big/intmarsh_test.go13
2 files changed, 17 insertions, 1 deletions
diff --git a/src/math/big/intmarsh.go b/src/math/big/intmarsh.go
index c1422e2710..ce429ffc11 100644
--- a/src/math/big/intmarsh.go
+++ b/src/math/big/intmarsh.go
@@ -67,7 +67,10 @@ func (z *Int) UnmarshalText(text []byte) error {
// MarshalJSON implements the json.Marshaler interface.
func (x *Int) MarshalJSON() ([]byte, error) {
- return x.MarshalText()
+ if x == nil {
+ return []byte("null"), nil
+ }
+ return x.abs.itoa(x.neg, 10), nil
}
// UnmarshalJSON implements the json.Unmarshaler interface.
diff --git a/src/math/big/intmarsh_test.go b/src/math/big/intmarsh_test.go
index f82956ceaf..8e7d29f9dd 100644
--- a/src/math/big/intmarsh_test.go
+++ b/src/math/big/intmarsh_test.go
@@ -97,6 +97,19 @@ func TestIntJSONEncoding(t *testing.T) {
}
}
+func TestIntJSONEncodingNil(t *testing.T) {
+ var x *Int
+ b, err := x.MarshalJSON()
+ if err != nil {
+ t.Fatalf("marshaling of nil failed: %s", err)
+ }
+ got := string(b)
+ want := "null"
+ if got != want {
+ t.Fatalf("marshaling of nil failed: got %s want %s", got, want)
+ }
+}
+
func TestIntXMLEncoding(t *testing.T) {
for _, test := range encodingTests {
for _, sign := range []string{"", "+", "-"} {