diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-18 21:57:39 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-18 22:45:39 -0700 |
commit | edfc7aa91b542978ce28eb109b99a257650b62b4 (patch) | |
tree | 3bc300355b7843a2c2ba3a0ec5db4346cdc87965 /reencode.go | |
parent | cf75ff06887d7bbb5bbbd682587b9d3f5e474670 (diff) |
decode_scan, jsonparse: Rework the behavior to make a bit more sense
- decode_scan: Don't have .Reset() re-play an erroring rune
- decode_Scan: Have RuneTypeEOF always be zero-width
- jsonparse: Don't replace syntax errors with RuneTypeEOF if there's no barrier
Diffstat (limited to 'reencode.go')
-rw-r--r-- | reencode.go | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/reencode.go b/reencode.go index 7e9b5ff..0745c43 100644 --- a/reencode.go +++ b/reencode.go @@ -276,7 +276,6 @@ func (enc *ReEncoder) Close() error { } func (enc *ReEncoder) handleRune(c rune, size int) { -rehandle: t, err := enc.par.HandleRune(c) if err != nil { enc.err = &ReEncodeSyntaxError{ @@ -293,16 +292,14 @@ rehandle: return } if t == jsonparse.RuneTypeEOF { - if enc.allowMultipleValues && len(enc.barriers) == 0 { - enc.par.Reset() - goto rehandle - } else { - enc.err = &ReEncodeSyntaxError{ - Err: fmt.Errorf("invalid character %q after top-level value", c), - Offset: enc.inputPos, - } - return + if len(enc.barriers) == 0 { + panic(fmt.Errorf("should not happen: EOF for rune %q without write barriers", c)) } + enc.err = &ReEncodeSyntaxError{ + Err: fmt.Errorf("invalid character %q after top-level value", c), + Offset: enc.inputPos, + } + return } enc.inputPos += int64(size) |