diff options
Diffstat (limited to 'src/encoding')
| -rw-r--r-- | src/encoding/json/encode_test.go | 15 | ||||
| -rw-r--r-- | src/encoding/json/stream.go | 6 |
2 files changed, 17 insertions, 4 deletions
diff --git a/src/encoding/json/encode_test.go b/src/encoding/json/encode_test.go index 13e765afa3..507581feed 100644 --- a/src/encoding/json/encode_test.go +++ b/src/encoding/json/encode_test.go @@ -440,7 +440,9 @@ func TestIssue6458(t *testing.T) { t.Fatal(err) } - if want := `{"M":"ImZvbyI="}`; string(b) != want { + // Until Go 1.8, this generated `{"M":"ImZvbyI="}`. + // See https://github.com/golang/go/issues/14493#issuecomment-255857318 + if want := `{"M":"foo"}`; string(b) != want { t.Errorf("Marshal(x) = %#q; want %#q", b, want) } } @@ -717,3 +719,14 @@ func TestMarshalFloat(t *testing.T) { test(0, 32) test(math.Copysign(0, -1), 32) } + +func TestMarshalRawMessageValue(t *testing.T) { + const val = "\"some value\"" + b, err := Marshal(RawMessage(val)) + if err != nil { + t.Fatal(err) + } + if string(b) != val { + t.Errorf("got %q; want %q", b, val) + } +} diff --git a/src/encoding/json/stream.go b/src/encoding/json/stream.go index 87f0e57c6c..4c350fdd5e 100644 --- a/src/encoding/json/stream.go +++ b/src/encoding/json/stream.go @@ -246,9 +246,9 @@ func (enc *Encoder) SetEscapeHTML(on bool) { // be used to delay JSON decoding or precompute a JSON encoding. type RawMessage []byte -// MarshalJSON returns *m as the JSON encoding of m. -func (m *RawMessage) MarshalJSON() ([]byte, error) { - return *m, nil +// MarshalJSON returns m as the JSON encoding of m. +func (m RawMessage) MarshalJSON() ([]byte, error) { + return m, nil } // UnmarshalJSON sets *m to a copy of data. |
