aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShenghou Ma <minux.ma@gmail.com>2013-04-30 11:21:48 +0800
committerShenghou Ma <minux.ma@gmail.com>2013-04-30 11:21:48 +0800
commit5c20a4f2608f80ca6a81b76b2e8b5df15128b3f3 (patch)
treef47bc7662648e18de252993c30cf1f35977cac2f
parentb42c8294ebe5bde8e7368716f909385cf7be148d (diff)
downloadgo-5c20a4f2608f80ca6a81b76b2e8b5df15128b3f3.tar.gz
go-5c20a4f2608f80ca6a81b76b2e8b5df15128b3f3.zip
encoding/json: document that marshaling invalid utf-8 sequence will return error
Also added docs for InvalidUTF8Error. Fixes #5360. R=golang-dev, adg, r CC=golang-dev https://golang.org/cl/8926046
-rw-r--r--src/pkg/encoding/json/encode.go8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/pkg/encoding/json/encode.go b/src/pkg/encoding/json/encode.go
index fd4239c163..85727ba61c 100644
--- a/src/pkg/encoding/json/encode.go
+++ b/src/pkg/encoding/json/encode.go
@@ -39,8 +39,8 @@ import (
//
// Floating point, integer, and Number values encode as JSON numbers.
//
-// String values encode as JSON strings, with each invalid UTF-8 sequence
-// replaced by the encoding of the Unicode replacement character U+FFFD.
+// String values encode as JSON strings. InvalidUTF8Error will be returned
+// if an invalid UTF-8 sequence is encountered.
// The angle brackets "<" and ">" are escaped to "\u003c" and "\u003e"
// to keep some browsers from misinterpreting JSON output as HTML.
//
@@ -200,8 +200,10 @@ func (e *UnsupportedValueError) Error() string {
return "json: unsupported value: " + e.Str
}
+// An InvalidUTF8Error is returned by Marshal when attempting
+// to encode a string value with invalid UTF-8 sequences.
type InvalidUTF8Error struct {
- S string
+ S string // the whole string value that caused the error
}
func (e *InvalidUTF8Error) Error() string {