Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit ec1cd74

Browse files
committed
[[ Bug 20488 ]] Ensure put throws when expecting preposition
This patch ensures that the put command throws an error if it parses a token when expecting a preposition and it isn't one. Previously the command backed up and returned normal resulting in the anomaly that anything after `put <expression>` could be treated as a second statement without a newline or `;` present.
1 parent a557dc3 commit ec1cd74

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

docs/notes/bugfix-20488.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Ensure the put command throws an error when a preposition is expected and not found

engine/src/cmds.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -844,8 +844,8 @@ Parse_stat MCPut::parse(MCScriptPoint &sp)
844844

845845
if (sp.lookup(SP_FACTOR, te) != PS_NORMAL || te->type != TT_PREP)
846846
{
847-
sp.backup();
848-
return PS_NORMAL;
847+
MCperror->add(PE_PUT_BADPREP, sp);
848+
return PS_ERROR;
849849
}
850850
prep = (Preposition_type)te->which;
851851
if (prep != PT_BEFORE && prep != PT_INTO && prep != PT_AFTER)

tests/lcs/parser/put.parsertest

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
%% Copyright (C) 2018 LiveCode Ltd.
2+
%%
3+
%% This file is part of LiveCode.
4+
%%
5+
%% LiveCode is free software; you can redistribute it and/or modify it under
6+
%% the terms of the GNU General Public License v3 as published by the Free
7+
%% Software Foundation.
8+
%%
9+
%% LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
10+
%% WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
%% for more details.
13+
%%
14+
%% You should have received a copy of the GNU General Public License
15+
%% along with LiveCode. If not see <http://www.gnu.org/licenses/>.
16+
17+
%TEST PutPreposition
18+
on parse_test
19+
local tFoo, tBar
20+
put tFoo tBar %{AFTER_BADPREP}
21+
end parse_test
22+
%EXPECT PASS
23+
%ERROR PE_PUT_BADPREP AT AFTER_BADPREP
24+
%ENDTEST

0 commit comments

Comments
 (0)