Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions decoder/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,28 @@ func TestDecodeOption(t *testing.T) {
assert.NoError(t, err)
}

func TestDecoderSequential(t *testing.T) {
// the first value is long enough to push the next value's start
// offset well past the internal padding, exercising the position
// handling when decoding multiple values from one buffer
first := `"` + strings.Repeat("A", 200) + `"`
second := `{"key":"hello world","n":12345}`
s := first + " " + second

d := NewDecoder(s)

var v1 string
assert.NoError(t, d.Decode(&v1))
assert.Equal(t, strings.Repeat("A", 200), v1)

var v2 map[string]interface{}
assert.NoError(t, d.Decode(&v2))

var ref map[string]interface{}
assert.NoError(t, json.Unmarshal([]byte(second), &ref))
assert.Equal(t, ref, v2)
}

func decode(s string, v interface{}, copy bool) (int, error) {
d := NewDecoder(s)
if copy {
Expand Down
2 changes: 1 addition & 1 deletion internal/decoder/optdec/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func newParser(data string, pos int, opt uint64) *Parser {
p.Utf8Inv = true
p.start = uintptr((*rt.GoString)(unsafe.Pointer(&p.Json)).Ptr)
} else {
p.Json = data
p.Json = data[pos:]
// TODO: prevent too large JSON
p.padded = append(p.padded, data[pos:]...)
p.padded = append(p.padded, padding...)
Expand Down
Loading