Fix skipValue

This commit is contained in:
Masaaki Goshima 2020-11-27 17:41:47 +09:00
parent 7421d82c43
commit 7f97aca5e6
2 changed files with 19 additions and 2 deletions

View File

@ -25,9 +25,16 @@ func skipValue(buf []byte, cursor int64) (int64, error) {
braceCount := 0
bracketCount := 0
buflen := int64(len(buf))
start := cursor
for {
switch buf[cursor] {
case '\000':
case nul:
if start == cursor {
return cursor, errUnexpectedEndOfJSON("value of object", cursor)
}
if braceCount == 0 && bracketCount == 0 {
return cursor, nil
}
return cursor, errUnexpectedEndOfJSON("value of object", cursor)
case '{':
braceCount++
@ -40,6 +47,9 @@ func skipValue(buf []byte, cursor int64) (int64, error) {
}
case ']':
bracketCount--
if braceCount == 0 && bracketCount == -1 {
return cursor, nil
}
case ',':
if bracketCount == 0 && braceCount == 0 {
return cursor, nil

View File

@ -111,12 +111,19 @@ func (s *stream) skipValue() error {
s.skipWhiteSpace()
braceCount := 0
bracketCount := 0
start := s.cursor
for {
switch s.char() {
case nul:
if s.read() {
continue
}
if start == s.cursor {
return errUnexpectedEndOfJSON("value of object", s.totalOffset())
}
if braceCount == 0 && bracketCount == 0 {
return nil
}
return errUnexpectedEndOfJSON("value of object", s.totalOffset())
case '{':
braceCount++
@ -129,7 +136,7 @@ func (s *stream) skipValue() error {
}
case ']':
bracketCount--
if braceCount == 0 && bracketCount == 0 {
if braceCount == 0 && bracketCount == -1 {
return nil
}
case ',':