diff --git a/src/scanner.c b/src/scanner.c index 219c89600f..200c8950f8 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -711,8 +711,10 @@ static void GetStr(void) // check for error conditions if (c == '\n') SyntaxError("String must not include "); - if (c == '\377') + if (c == '\377') { + *STATE(In) = '\0'; SyntaxError("String must end with \" before end of file"); + } STATE(ValueObj) = string; STATE(Symbol) = S_STRING; @@ -780,8 +782,10 @@ static void GetTripStr(void) CSTR_STRING(string)[len] = '\0'; // check for error conditions - if (c == '\377') + if (c == '\377') { + *STATE(In) = '\0'; SyntaxError("String must end with \"\"\" before end of file"); + } STATE(ValueObj) = string; STATE(Symbol) = S_STRING; diff --git a/tst/testinstall/kernel/scanner.tst b/tst/testinstall/kernel/scanner.tst index 8c37a96d9b..85e5cbb78a 100644 --- a/tst/testinstall/kernel/scanner.tst +++ b/tst/testinstall/kernel/scanner.tst @@ -119,5 +119,28 @@ a.x111111111111111111111111111111111111111111111111111111111111111111111111111\ \ ^ +# +# test EOF inside a string literal +# +gap> EvalString("\"123"); +Syntax error: String must end with " before end of file in stream:1 +^ +Syntax error: ; expected in stream:1 +^ +Error, Could not evaluate string. + +gap> EvalString("\"\"\"123"); +Syntax error: String must end with """ before end of file in stream:1 +^ +Syntax error: ; expected in stream:1 +^ +Error, Could not evaluate string. + +gap> obj := """ +Syntax error: String must end with """ before end of file in stream:2 +^ +Syntax error: ; expected in stream:2 +^ + # gap> STOP_TEST("kernel/scanner.tst", 1);