Don't allow floats starting with a dot

This commit is contained in:
Thomas Pelletier
2013-12-10 17:17:15 +01:00
parent c743c90315
commit 278c4d97ec
3 changed files with 21 additions and 0 deletions
+7
View File
@@ -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 {
+2
View File
@@ -141,6 +141,8 @@ func parseRvalue(p *parser) interface{} {
return val
case tokenLeftBracket:
return parseArray(p)
case tokenError:
panic(tok.val)
}
panic("never reached")
+12
View File
@@ -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" {