Merge branch 'master' into fix-issue-278

This commit is contained in:
Nao Yonashiro 2021-08-25 11:23:59 +09:00 committed by GitHub
commit ae9148555a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -239,7 +239,15 @@ func stringBytes(s *Stream) ([]byte, error) {
fallthrough fallthrough
default: default:
// multi bytes character // multi bytes character
r, size := utf8.DecodeRune(s.buf[cursor:]) if !utf8.FullRune(s.buf[cursor : len(s.buf)-1]) {
s.cursor = cursor
if s.read() {
_, cursor, p = s.stat()
continue
}
goto ERROR
}
r, size := utf8.DecodeRune(s.buf[cursor:])
if r == utf8.RuneError { if r == utf8.RuneError {
s.buf = append(append(append([]byte{}, s.buf[:cursor]...), runeErrBytes...), s.buf[cursor+1:]...) s.buf = append(append(append([]byte{}, s.buf[:cursor]...), runeErrBytes...), s.buf[cursor+1:]...)
cursor += runeErrBytesLen cursor += runeErrBytesLen

View File

@ -14,6 +14,7 @@ import (
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"reflect" "reflect"
"strconv"
"strings" "strings"
"testing" "testing"
@ -502,6 +503,19 @@ func TestGzipStreaming(t *testing.T) {
} }
} }
func TestLongUTF8(t *testing.T) {
want := strings.Repeat("あ", 342)
r := strings.NewReader(strconv.Quote(want))
var got string
if err := json.NewDecoder(r).Decode(&got); err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if got != want {
t.Errorf("string %q; want = %q", got, want)
}
}
func TestIssue278(t *testing.T) { func TestIssue278(t *testing.T) {
a := `{"嗷嗷":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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