Don't allow floats starting with a dot
This commit is contained in:
@@ -234,6 +234,10 @@ func lexRvalue(l *lexer) stateFn {
|
||||
return lexNumber
|
||||
}
|
||||
|
||||
if next == '.' {
|
||||
return l.errorf("cannot start float with a dot")
|
||||
}
|
||||
|
||||
if isSpace(next) {
|
||||
l.ignore()
|
||||
}
|
||||
@@ -416,6 +420,9 @@ func lexNumber(l *lexer) stateFn {
|
||||
l.backup()
|
||||
break
|
||||
}
|
||||
if point_seen && !digit_seen {
|
||||
return l.errorf("cannot start float with a dot")
|
||||
}
|
||||
}
|
||||
|
||||
if !digit_seen {
|
||||
|
||||
@@ -141,6 +141,8 @@ func parseRvalue(p *parser) interface{} {
|
||||
return val
|
||||
case tokenLeftBracket:
|
||||
return parseArray(p)
|
||||
case tokenError:
|
||||
panic(tok.val)
|
||||
}
|
||||
|
||||
panic("never reached")
|
||||
|
||||
@@ -210,6 +210,18 @@ func TestEmptyIntermediateTable(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFloatsWithoutLeadingZeros(t *testing.T) {
|
||||
_, err := Load("a = .42")
|
||||
if err.Error() != "cannot start float with a dot" {
|
||||
t.Error("Bad error message:", err.Error())
|
||||
}
|
||||
|
||||
_, err = Load("a = -.42")
|
||||
if err.Error() != "cannot start float with a dot" {
|
||||
t.Error("Bad error message:", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestMissingFile(t *testing.T) {
|
||||
_, err := LoadFile("foo.toml")
|
||||
if err.Error() != "open foo.toml: no such file or directory" {
|
||||
|
||||
Reference in New Issue
Block a user