Don't allow invalid escape sequences

This commit is contained in:
Thomas Pelletier
2013-12-10 17:34:11 +01:00
parent e8d5dbf787
commit a34fc5f051
2 changed files with 11 additions and 0 deletions
+3
View File
@@ -358,6 +358,9 @@ func lexString(l *lexer) stateFn {
return l.errorf("invalid unicode escape: \\u" + code)
}
growing_string += string(rune(intcode))
} else if l.follow("\\") {
l.pos += 1
return l.errorf("invalid escape sequence: \\" + string(l.peek()))
} else {
growing_string += string(l.peek())
}
+8
View File
@@ -292,6 +292,14 @@ func TestDoubleEqualKey(t *testing.T) {
})
}
func TestInvalidEsquapeSequence(t *testing.T) {
testFlow(t, "foo = \"\\x\"", []token{
token{tokenKey, "foo"},
token{tokenEqual, "="},
token{tokenError, "invalid escape sequence: \\x"},
})
}
func TestKeyEqualNumber(t *testing.T) {
testFlow(t, "foo = 42", []token{
token{tokenKey, "foo"},