Skip to content

Commit

Permalink
Issue #5: properly validate 001 number
Browse files Browse the repository at this point in the history
  • Loading branch information
valyala committed Jun 16, 2018
1 parent 8ad826f commit 285c99e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions validate.go
Expand Up @@ -249,15 +249,15 @@ func validateNumber(s string) (string, error) {
}
i++
}
if i == 0 {
if i <= 0 {
return s, fmt.Errorf("expecting 0..9 digit, got %c", s[0])
}
if i >= len(s) {
return "", nil
}
if s[0] == '0' && i != 1 {
return s, fmt.Errorf("unexpected number starting from 0")
}
if i >= len(s) {
return "", nil
}
if s[i] == '.' {
// Validate fractional part
s = s[i+1:]
Expand Down
1 change: 1 addition & 0 deletions validate_test.go
Expand Up @@ -99,6 +99,7 @@ func TestValidate(t *testing.T) {
"123.",
"123.345",
"001 ",
"001",

// object
"{}",
Expand Down

0 comments on commit 285c99e

Please sign in to comment.