summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--lexer.c4
-rw-r--r--tests/custom/03_bugs/16_hang_on_regexp_at_eof9
-rwxr-xr-xtests/custom/run_tests.sh5
3 files changed, 16 insertions, 2 deletions
diff --git a/lexer.c b/lexer.c
index 0fbea79..6e1dcd9 100644
--- a/lexer.c
+++ b/lexer.c
@@ -663,8 +663,8 @@ parse_regexp(uc_lexer *lex)
case UT_LEX_PARSE_REGEX_FLAGS:
rv = (uc_token *)lex->lookbehind;
- while (lex->bufstart < lex->bufend) {
- switch (lex->bufstart[0]) {
+ while (lex->bufstart < lex->bufend || lex->eof) {
+ switch (lex->eof ? EOF : lex->bufstart[0]) {
case 'g':
buf_consume(lex, 1);
is_reg_global = true;
diff --git a/tests/custom/03_bugs/16_hang_on_regexp_at_eof b/tests/custom/03_bugs/16_hang_on_regexp_at_eof
new file mode 100644
index 0000000..d8702ca
--- /dev/null
+++ b/tests/custom/03_bugs/16_hang_on_regexp_at_eof
@@ -0,0 +1,9 @@
+When parsing a regexp literal at the end of the source buffer, the lexer
+ended up in an infinite loop watining for a non-flag character.
+
+-- Expect stdout --
+-- End --
+
+-- Testcase --
+{% /a/
+-- End (no-eol) --
diff --git a/tests/custom/run_tests.sh b/tests/custom/run_tests.sh
index 61b116f..db64021 100755
--- a/tests/custom/run_tests.sh
+++ b/tests/custom/run_tests.sh
@@ -28,6 +28,11 @@ extract_sections() {
outfile=$(printf "%s/%03d.%s" "$dir" $count "$tag")
printf "" > "$outfile"
;;
+ "-- End (no-eol) --")
+ truncate -s -1 "$outfile"
+ tag=""
+ outfile=""
+ ;;
"-- End --")
tag=""
outfile=""