Don't allow invalid escape sequences
This commit is contained in:
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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"},
|
||||
|
||||
Reference in New Issue
Block a user