aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/encoding/json/decode_test.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2013-02-14 14:56:01 -0500
committerRuss Cox <rsc@golang.org>2013-02-14 14:56:01 -0500
commit30359a55c264dba2076c86f40a3c7c915889b9df (patch)
treee23bae2e96fd69ad597853aa48bb18dec5acc634 /src/pkg/encoding/json/decode_test.go
parent31072e41f4e2ed0a135c46816cb2a65daba12540 (diff)
downloadgo-30359a55c264dba2076c86f40a3c7c915889b9df.tar.xz
encoding/json: document and test use of unicode.ReplacementChar
Fixes #4783. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/7314099
Diffstat (limited to 'src/pkg/encoding/json/decode_test.go')
-rw-r--r--src/pkg/encoding/json/decode_test.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/pkg/encoding/json/decode_test.go b/src/pkg/encoding/json/decode_test.go
index 524a9989fe..1ce26f8fb3 100644
--- a/src/pkg/encoding/json/decode_test.go
+++ b/src/pkg/encoding/json/decode_test.go
@@ -330,6 +330,43 @@ var unmarshalTests = []unmarshalTest{
ptr: new(S10),
out: S10{S13: S13{S8: S8{S9: S9{Y: 2}}}},
},
+
+ // invalid UTF-8 is coerced to valid UTF-8.
+ {
+ in: "\"hello\xffworld\"",
+ ptr: new(string),
+ out: "hello\ufffdworld",
+ },
+ {
+ in: "\"hello\xc2\xc2world\"",
+ ptr: new(string),
+ out: "hello\ufffd\ufffdworld",
+ },
+ {
+ in: "\"hello\xc2\xffworld\"",
+ ptr: new(string),
+ out: "hello\ufffd\ufffdworld",
+ },
+ {
+ in: "\"hello\\ud800world\"",
+ ptr: new(string),
+ out: "hello\ufffdworld",
+ },
+ {
+ in: "\"hello\\ud800\\ud800world\"",
+ ptr: new(string),
+ out: "hello\ufffd\ufffdworld",
+ },
+ {
+ in: "\"hello\\ud800\\ud800world\"",
+ ptr: new(string),
+ out: "hello\ufffd\ufffdworld",
+ },
+ {
+ in: "\"hello\xed\xa0\x80\xed\xb0\x80world\"",
+ ptr: new(string),
+ out: "hello\ufffd\ufffd\ufffd\ufffd\ufffd\ufffdworld",
+ },
}
func TestMarshal(t *testing.T) {