1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

toml: add better float validation (#12640)

This commit is contained in:
Larpon
2021-12-02 10:16:55 +01:00
committed by GitHub
parent f7926ec9a4
commit 9cf7af0c75
2 changed files with 16 additions and 9 deletions

View File

@@ -210,6 +210,14 @@ fn (c Checker) check_number(num ast.Number) ? {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' numbers like "$lit" (float) can not have decimal points on either side of the exponent notation in ...${c.excerpt(num.pos)}...')
}
// Check if it contains other chars than the allowed
for r in lit {
if r !in [`0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `.`, `e`, `E`, `-`, `+`,
`_`] {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' numbers like "$lit" (float) can not contain `${byte(r).ascii_str()}` in ...${c.excerpt(num.pos)}...')
}
}
} else {
if lit.len > 1 && lit.starts_with('0') && lit[1] !in [`b`, `o`, `x`] {
ascii = byte(lit[0]).ascii_str()