Skip to content

Commit abdbcb1

Browse files
committed
codec: nextValueBytes should not include last read token when reading a json number
Fixes #427
1 parent af1615e commit abdbcb1

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

codec/json.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,11 @@ func (d *jsonDecDriver[T]) nextValueBytes() []byte {
630630
switch d.tok {
631631
default:
632632
_, d.tok = d.r.jsonReadNum()
633+
// special case: trim last read token if a valid byte in stream
634+
if d.tok != 0 {
635+
vv := d.r.stopRecording()
636+
return vv[:len(vv)-1]
637+
}
633638
case 'n':
634639
d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3())
635640
case 'f':

codec/json.mono.generated.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3615,6 +3615,11 @@ func (d *jsonDecDriverBytes) nextValueBytes() []byte {
36153615
switch d.tok {
36163616
default:
36173617
_, d.tok = d.r.jsonReadNum()
3618+
3619+
if d.tok != 0 {
3620+
vv := d.r.stopRecording()
3621+
return vv[:len(vv)-1]
3622+
}
36183623
case 'n':
36193624
d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3())
36203625
case 'f':
@@ -7773,6 +7778,11 @@ func (d *jsonDecDriverIO) nextValueBytes() []byte {
77737778
switch d.tok {
77747779
default:
77757780
_, d.tok = d.r.jsonReadNum()
7781+
7782+
if d.tok != 0 {
7783+
vv := d.r.stopRecording()
7784+
return vv[:len(vv)-1]
7785+
}
77767786
case 'n':
77777787
d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3())
77787788
case 'f':

0 commit comments

Comments
 (0)