Skip to content

Commit edccb81

Browse files
authored
fix: do not reject a maximal-length number followed by a delimiter (#15)
1 parent 83b0bdd commit edccb81

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

‎integer.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,20 @@ func parseNumber(s *scanner) (interface{}, error) {
5959
)
6060

6161
for s.off < len(s.data) {
62-
size := s.off - start
63-
if (t == typeInteger && (size >= 15)) || size >= 16 {
64-
return 0, &UnmarshalError{s.off, ErrNumberOutOfRange}
65-
}
66-
6762
c := s.data[s.off]
6863
if isDigit(c) {
6964
s.off++
7065

66+
// The length limit applies to the consumed digits, not to the delimiter that follows them.
67+
if size := s.off - start; (t == typeInteger && size > 15) || size > 16 {
68+
return 0, &UnmarshalError{s.off, ErrNumberOutOfRange}
69+
}
70+
7171
continue
7272
}
7373

7474
if t == typeInteger && c == '.' {
75-
if size > maxDigit {
75+
if s.off-start > maxDigit {
7676
return 0, &UnmarshalError{s.off, ErrNumberOutOfRange}
7777
}
7878

‎integer_test.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ func TestParseIntegerOrDecimal(t *testing.T) {
5959
{"10.", 0, true},
6060
{"10.1234", 0, true},
6161
{"-", 0, true},
62+
{"123456789012345, 1", int64(123456789012345), false},
63+
{"123456789012.123, 1.1", 123456789012.123, false},
6264
{"1234567890123456", 0, true},
6365
{"123456789012345.6", 0, true},
6466
{"1234567890123.", 0, true},

0 commit comments

Comments
 (0)