1
0
mirror of https://github.com/json-iterator/go.git synced 2025-02-07 19:30:06 +02:00

control character in string is invalid

This commit is contained in:
Tao Wen 2017-07-10 15:13:31 +08:00
parent a447a8f797
commit c38e47d169
2 changed files with 9 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package jsoniter
import (
"unicode/utf16"
"fmt"
)
// ReadString read string from iterator
@ -16,6 +17,10 @@ func (iter *Iterator) ReadString() (ret string) {
return ret
} else if c == '\\' {
break
} else if c < ' ' {
iter.ReportError("ReadString",
fmt.Sprintf(`invalid control character found: %d`, c))
return
}
}
return iter.readStringSlowPath()

View File

@ -19,7 +19,10 @@ func Test_read_string(t *testing.T) {
`"\"`,
`"\\\"`,
"\"\n\"",
`navy`,
}
for i :=0; i < 32; i++ {
// control characters are invalid
badInputs = append(badInputs, string([]byte{'"', byte(i), '"'}))
}
for _, input := range badInputs {