commit 8c1ca1afada2eca337fd466a79e6fb46d2ffecfe
parent 2fc399c5e592dc6c8114e790510d4b232f0d341a
Author: Alexey Yerin <yyp@disroot.org>
Date: Sun, 19 Feb 2023 22:52:39 +0300
hare::lex: error out when encountering an invalid escape sequence
Signed-off-by: Alexey Yerin <yyp@disroot.org>
Diffstat:
2 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/hare/lex/+test.ha b/hare/lex/+test.ha
@@ -322,6 +322,16 @@ fn loc(line: uint, col: uint) location = location {
const s = lex(&lexer) as error as syntax;
assert(s.1 == "Source file is not valid UTF-8");
+
+ // Regression: invalid escape sequences such as "\^" used to casue a
+ // crash
+ const in = ['"': u8, '\\': u8, '^': u8, '"': u8];
+
+ let buf = bufio::fixed(in, mode::READ);
+ let lexer = init(&buf, "<test>");
+
+ const s = lex(&lexer) as error as syntax;
+ assert(s.1 == "unknown escape sequence");
};
diff --git a/hare/lex/lex.ha b/hare/lex/lex.ha
@@ -218,6 +218,8 @@ fn lex_rune(lex: *lexer, loc: location) (rune | error) = {
return lex_unicode(lex, loc, 4);
case 'U' =>
return lex_unicode(lex, loc, 8);
+ case =>
+ return syntaxerr(mkloc(lex), "unknown escape sequence");
};
};