forked from mirror/go-json
Merge branch 'master' into fix-issue-278
This commit is contained in:
commit
ae9148555a
|
@ -239,6 +239,14 @@ func stringBytes(s *Stream) ([]byte, error) {
|
||||||
fallthrough
|
fallthrough
|
||||||
default:
|
default:
|
||||||
// multi bytes character
|
// multi bytes character
|
||||||
|
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:])
|
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:]...)
|
||||||
|
|
|
@ -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 := `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