Skip to content

Commit

Permalink
fix: properly handle CR character
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Jul 20, 2023
1 parent 17ee314 commit c7bc3f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions dec_float.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ func init() {
floatDigits[','] = endOfNumber
floatDigits[']'] = endOfNumber
floatDigits['}'] = endOfNumber
floatDigits[' '] = endOfNumber
floatDigits['\t'] = endOfNumber
floatDigits['\n'] = endOfNumber

for ch, isSpace := range spaceSet {
if isSpace == 1 {
floatDigits[ch] = endOfNumber
}
}
for i := int8('0'); i <= int8('9'); i++ {
floatDigits[i] = i - int8('0')
}
Expand Down
5 changes: 3 additions & 2 deletions int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,12 +434,13 @@ func TestReadInt64(t *testing.T) {
`12345678901`,
`9223372036854775807`,
`-9223372036854775808`,
"-9223372036854775808\r",
}
for i, input := range inputs {
input := input
t.Run(fmt.Sprintf("Test%d", i+1), createTestCase(input, func(t *testing.T, d *Decoder) error {
should := require.New(t)
expected, err := strconv.ParseInt(input, 10, 64)
expected, err := strconv.ParseInt(strings.Trim(input, "\r"), 10, 64)
should.NoError(err)
v, err := d.Int64()
should.NoError(err)
Expand All @@ -455,7 +456,7 @@ func TestReadInt64(t *testing.T) {
i := 0

return d.Arr(func(d *Decoder) error {
expected, err := strconv.ParseInt(inputs[i], 10, 64)
expected, err := strconv.ParseInt(strings.Trim(inputs[i], "\r"), 10, 64)
should.NoError(err)

v, err := d.Int64()
Expand Down

0 comments on commit c7bc3f6

Please sign in to comment.