mirror of
https://github.com/json-iterator/go.git
synced 2024-11-27 08:30:57 +02:00
#153 fix invalid utf8 using same implementation as the standard library
This commit is contained in:
parent
f706335302
commit
36b14963da
@ -286,8 +286,11 @@ func writeStringSlowPathWithHTMLEscaped(stream *Stream, i int, s string, valLen
|
||||
}
|
||||
c, size := utf8.DecodeRuneInString(s[i:])
|
||||
if c == utf8.RuneError && size == 1 {
|
||||
if start < i {
|
||||
stream.WriteRaw(s[start:i])
|
||||
}
|
||||
stream.WriteRaw(`\ufffd`)
|
||||
i++
|
||||
stream.WriteRaw(s[start:i])
|
||||
start = i
|
||||
continue
|
||||
}
|
||||
|
@ -122,8 +122,11 @@ func Test_invalid_number(t *testing.T) {
|
||||
obj := Message{}
|
||||
decoder := ConfigCompatibleWithStandardLibrary.NewDecoder(bytes.NewBufferString(`{"number":"5"}`))
|
||||
err := decoder.Decode(&obj)
|
||||
result, err := ConfigCompatibleWithStandardLibrary.Marshal(err.Error())
|
||||
invalidStr := err.Error()
|
||||
result, err := ConfigCompatibleWithStandardLibrary.Marshal(invalidStr)
|
||||
should := require.New(t)
|
||||
should.Nil(err)
|
||||
should.Contains(string(result), "\xff")
|
||||
result2, err := json.Marshal(invalidStr)
|
||||
should.Nil(err)
|
||||
should.Equal(string(result2), string(result))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user