diff --git a/feature_stream_string.go b/feature_stream_string.go index 2856836..8655f93 100644 --- a/feature_stream_string.go +++ b/feature_stream_string.go @@ -286,9 +286,8 @@ 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]) - } + i++ + stream.WriteRaw(s[start:i]) start = i continue } diff --git a/jsoniter_invalid_test.go b/jsoniter_invalid_test.go index f328a16..ba864b4 100644 --- a/jsoniter_invalid_test.go +++ b/jsoniter_invalid_test.go @@ -5,6 +5,7 @@ import ( "github.com/stretchr/testify/require" "io" "testing" + "bytes" ) func Test_missing_object_end(t *testing.T) { @@ -113,3 +114,16 @@ func Test_chan(t *testing.T) { should.Nil(err) should.Equal(``, str) } + +func Test_invalid_number(t *testing.T) { + type Message struct { + Number int `json:"number"` + } + obj := Message{} + decoder := ConfigCompatibleWithStandardLibrary.NewDecoder(bytes.NewBufferString(`{"number":"5"}`)) + err := decoder.Decode(&obj) + result, err := ConfigCompatibleWithStandardLibrary.Marshal(err.Error()) + should := require.New(t) + should.Nil(err) + should.Contains(string(result), "\xff") +}