json: check for invalid UTF-8

Fixes #1250.

R=r
CC=golang-dev
https://golang.org/cl/3562042
This commit is contained in:
Russ Cox 2010-12-13 15:51:11 -05:00
parent 3a2ba994b6
commit 287e45e241
2 changed files with 52 additions and 11 deletions

View file

@ -102,6 +102,20 @@ func TestMarshal(t *testing.T) {
}
}
func TestMarshalBadUTF8(t *testing.T) {
s := "hello\xffworld"
b, err := Marshal(s)
if err == nil {
t.Fatal("Marshal bad UTF8: no error")
}
if len(b) != 0 {
t.Fatal("Marshal returned data")
}
if _, ok := err.(*InvalidUTF8Error); !ok {
t.Fatal("Marshal did not return InvalidUTF8Error: %T %v", err, err)
}
}
func TestUnmarshal(t *testing.T) {
var scan scanner
for i, tt := range unmarshalTests {