Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,10 @@ static void GetStr(void)
// check for error conditions
if (c == '\n')
SyntaxError("String must not include <newline>");
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;
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 23 additions & 0 deletions tst/testinstall/kernel/scanner.tst
Original file line number Diff line number Diff line change
Expand Up @@ -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);