Floats and integers parsing fixes (#638)

* parser: fix scan of float with exp but no decimal
* decoder: validate leading zeros for decimals
This commit is contained in:
Thomas Pelletier
2021-10-22 22:25:56 -04:00
committed by GitHub
parent feb1830dcc
commit 4d7c9ddac7
4 changed files with 20 additions and 4 deletions
+14
View File
@@ -306,12 +306,26 @@ func parseIntBin(b []byte) (int64, error) {
return i, nil
}
func isSign(b byte) bool {
return b == '+' || b == '-'
}
func parseIntDec(b []byte) (int64, error) {
cleaned, err := checkAndRemoveUnderscoresIntegers(b)
if err != nil {
return 0, err
}
startIdx := 0
if isSign(cleaned[0]) {
startIdx++
}
if len(cleaned) > startIdx+1 && cleaned[startIdx] == '0' {
return 0, newDecodeError(b, "leading zero not allowed on decimal number")
}
i, err := strconv.ParseInt(string(cleaned), 10, 64)
if err != nil {
return 0, newDecodeError(b, "couldn't parse decimal number: %w", err)