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

Commit 6ecab4f

Browse files
Merge pull request #6317 from livecode/bugfix-20951
[[ Bugfix 20951 ]] Fixed bug causing garbage at end of repeat to be ignored
2 parents ce1a8cb + a9ad5d2 commit 6ecab4f

File tree

4 files changed

+97
-40
lines changed

4 files changed

+97
-40
lines changed

docs/notes/bugfix-20951.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Fix bug ignoring garbage values at end of repeat line

engine/src/keywords.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -703,12 +703,20 @@ Parse_stat MCRepeat::parse(MCScriptPoint &sp)
703703
return PS_ERROR;
704704
}
705705
if (sp.skip_token(SP_REPEAT, TT_UNDEFINED, RF_STEP) == PS_NORMAL)
706-
if (sp.parseexp(False, True, &step) != PS_NORMAL)
707-
{
708-
MCperror->add
709-
(PE_REPEAT_BADWITHSTARTEXP, sp);
710-
return PS_ERROR;
711-
}
706+
{
707+
if (sp.parseexp(False, True, &step) != PS_NORMAL)
708+
{
709+
MCperror->add
710+
(PE_REPEAT_BADWITHSTARTEXP, sp);
711+
return PS_ERROR;
712+
}
713+
}
714+
else if (sp.next(type) != PS_EOL)
715+
{
716+
MCperror -> add
717+
(PE_REPEAT_BADCOND, sp);
718+
return PS_ERROR;
719+
}
712720
break;
713721
default: /* repeat form */
714722
fprintf(stderr, "Repeat: ERROR bad control form\n");

extensions/script-libraries/drawing/drawing.livecodescript

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@ on extensionInitialize
2020
if the target is not me then
2121
pass extensionInitialize
2222
end if
23-
23+
2424
insert the script of me into back
25-
25+
2626
if the environment contains "development" then
2727
set the _ideoverride of me to true
2828
local tName
2929
put the short name of me into tName
30-
revSBAddDependencyForInclusion "extensions", tName, "externals", "XML"
30+
revSBAddDependencyForInclusion "extensions", tName, "externals", "XML"
3131
end if
32-
32+
3333
svgSpecLoad
3434
end extensionInitialize
3535

3636
on extensionFinalize
3737
if the target is not me then
3838
pass extensionFinalize
3939
end if
40-
40+
4141
remove the script of me from back
4242
end extensionFinalize
4343

@@ -539,7 +539,7 @@ private command _svgFlatten @xContext, @xElement
539539
end if
540540
end if
541541
end if
542-
542+
543543
/* Now all the processing for this element has been done, we process each
544544
* child, in order. */
545545
if xElement["content"] is an array then
@@ -809,7 +809,7 @@ private command _svgCompileTransform @xContext, pTransform, pBBox, @rCompiledTra
809809
_InternalError format("unknown transform '%s'", tTransform[1])
810810
break
811811
end switch
812-
put _svgTransformConcat(tMatrix, tNextMatrix) into tMatrix
812+
put _svgTransformConcat(tMatrix, tNextMatrix) into tMatrix
813813
end repeat
814814
put empty into rCompiledTransform
815815
if not _svgTransformIsIdentity(tMatrix) then
@@ -1009,7 +1009,7 @@ private command _svgCompileResolveGradient @xContext, pElement, @rGradient
10091009
if the number of elements in tColors > 0 then
10101010
put tColors into rGradient["colors"]
10111011
put tOffsets into rGradient["offsets"]
1012-
end if
1012+
end if
10131013
end if
10141014
end _svgCompileResolveGradient
10151015

@@ -1067,7 +1067,7 @@ private command _svgCompileSvg @xContext, pElement
10671067
else if tPreserveAspectRatio contains "yMax" then
10681068
add (tHeight - tViewBox[4] * tVScaleY) to tVTranslateY
10691069
end if
1070-
1070+
10711071
local tViewportMatrix
10721072
put _svgTransformTranslate(tVTranslateX, tVTranslateY) into tViewportMatrix
10731073
put _svgTransformConcat(tViewportMatrix, _svgTransformScale(tVScaleX, tVScaleY)) into tViewportMatrix
@@ -1170,7 +1170,7 @@ private command _svgCompileShape @xContext, pType, pBBox
11701170
if param(4) is an array then
11711171
put param(4) into tOperation[2]
11721172
else
1173-
repeat with tIndex = 4 to paramCount()
1173+
repeat with tIndex = 4 to the paramCount
11741174
put param(tIndex) into tOperation[2][tIndex - 3]
11751175
end repeat
11761176
end if
@@ -1243,8 +1243,10 @@ private function _svgBoxPoints pPoints
12431243
put pPoints[1] into tRight
12441244
put pPoints[2] into tTop
12451245
put pPoints[2] into tBottom
1246-
repeat with i = 1 to the number of elements in pPoints by 2
1247-
if pPoints[i] < tLeft then
1246+
local tNumberPoints
1247+
put the number of elements in pPoints into tNumberPoints
1248+
repeat with i = 1 to tNumberPoints step 2
1249+
if pPoints[i] < tLeft then
12481250
put pPoints[i] into tLeft
12491251
else if pPoints[i] > tRight then
12501252
put pPoints[i] into tRight
@@ -2367,7 +2369,7 @@ private function _svgParseTransformValue @xValue
23672369

23682370
local tArity
23692371
put the number of elements in tValues into tArity
2370-
2372+
23712373
switch tType
23722374
case "matrix"
23732375
if tArity is not 6 then
@@ -2886,10 +2888,10 @@ private command svgSpecLoad
28862888

28872889
/* Record the name of the new element. */
28882890
put word 2 of tLine into tCurrentElement["name"]
2889-
2891+
28902892
next repeat
28912893
end if
2892-
2894+
28932895
/* The 'property' and 'attribute' lines have the same format and define
28942896
* a feature. */
28952897
if tLineType is "property" or tLineType is "attribute" then
@@ -2899,7 +2901,7 @@ private command svgSpecLoad
28992901
_svgSpecError tCurrentRow, "no current element"
29002902
next repeat
29012903
end if
2902-
2904+
29032905
/* Properties must only be defined against the element with no
29042906
* name. */
29052907
if tLineType is "property" and \
@@ -2978,7 +2980,7 @@ private command svgSpecLoad
29782980

29792981
/* Add the feature to the current element's feature map. */
29802982
put tFeature into tCurrentElement[tLineType][tFeature["name"]]
2981-
2983+
29822984
next repeat
29832985
end if
29842986

@@ -3000,7 +3002,7 @@ private command svgSpecLoad
30003002
/* For named elements, the property array is a set of applicable
30013003
* properties. */
30023004
put true into tCurrentElement["property"][word 2 of tLine]
3003-
3005+
30043006
next repeat
30053007
end if
30063008

@@ -3126,53 +3128,53 @@ end _svgSpecError
31263128
*/
31273129
private function xmlImportFromFile pXMLFile
31283130
local tArray
3129-
3131+
31303132
local tTreeId
31313133
put revCreateXMLTreeFromFileWithNamespaces(pXMLFile, true, true, false) into tTreeId
3132-
3134+
31333135
if tTreeId begins with "xmlerr," then
31343136
throw tTreeId
31353137
end if
3136-
3138+
31373139
try
31383140
local tRootNode
31393141
put revXMLRootNode(tTreeId) into tRootNode
31403142
if tRootNode begins with "xmlerr," then
31413143
throw tRootNode
31423144
end if
3143-
3145+
31443146
put _xmlImportNode(tTreeId, revXMLRootNode(tTreeId)) into tArray
3145-
3147+
31463148
finally
31473149
revDeleteXMLTree tTreeId
31483150
end try
3149-
3151+
31503152
return tArray
31513153
end xmlImportFromFile
31523154

31533155
private function xmlImportFromText pXMLText
31543156
local tArray
3155-
3157+
31563158
local tTreeId
31573159
put revCreateXMLTreeWithNamespaces(pXMLText, true, true, false) into tTreeId
3158-
3160+
31593161
if tTreeId begins with "xmlerr," then
31603162
throw tTreeId
31613163
end if
3162-
3164+
31633165
try
31643166
local tRootNode
31653167
put revXMLRootNode(tTreeId) into tRootNode
31663168
if tRootNode begins with "xmlerr," then
31673169
throw tRootNode
31683170
end if
3169-
3171+
31703172
put _xmlImportNode(tTreeId, revXMLRootNode(tTreeId)) into tArray
3171-
3173+
31723174
finally
31733175
revDeleteXMLTree tTreeId
31743176
end try
3175-
3177+
31763178
return tArray
31773179
end xmlImportFromText
31783180

@@ -3195,7 +3197,7 @@ private function _xmlImportNode pTreeId, pNode
31953197
/* Extract the node type and index from the pNode path */
31963198
local tArray
31973199
_xmlImportNodeTypeAndIndex pNode, tArray["type"], tArray["index"]
3198-
3200+
31993201
-- First extract the attributes, these go into an 'attribute' field
32003202
-- as an array mapping attribute name to value
32013203
local tAttributes
@@ -3205,14 +3207,14 @@ private function _xmlImportNode pTreeId, pNode
32053207
end if
32063208
split tAttributes by return and "="
32073209
put tAttributes into tArray["features"]
3208-
3210+
32093211
-- Get the list of child nodes
32103212
local tChildNodes
32113213
put revXMLChildNames(pTreeId, pNode, return, empty, true, true) into tChildNodes
32123214
if tChildNodes begins with "xmlerr," then
32133215
throw tChildNodes
32143216
end if
3215-
3217+
32163218
/* If the list of child nodes of the element is not empty, then we
32173219
* recursively import each child node into a sequence; otherwise the node
32183220
* only contains text (or has no content) which we import as a string. */
@@ -3234,7 +3236,7 @@ private function _xmlImportNode pTreeId, pNode
32343236
/* The content of the node, whether it be just a string or a sequence of
32353237
* other nodes is placed in the 'content' key of the resulting node array. */
32363238
put tContent into tArray["content"]
3237-
3239+
32383240
return tArray
32393241
end _xmlImportNode
32403242

tests/lcs/parser/repeat.parsertest

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
%% Copyright (C) 2016 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+
%% REPEAT WITH no step
18+
%TEST RepeatWithNoStep
19+
on mouseUp
20+
repeat with i = 1 to 10
21+
end repeat
22+
end mouseUp
23+
%EXPECT PASS
24+
%SUCCESS
25+
%ENDTEST
26+
27+
%% Repeat With step
28+
%TEST RepeatWithCorrectStep
29+
on mouseUp
30+
repeat with i = 1 to 10 step 1
31+
end repeat
32+
end mouseUp
33+
%EXPECT PASS
34+
%SUCCESS
35+
%ENDTEST
36+
37+
%% Repeat with step should fail
38+
%TEST RepeatWithIncorrectStep
39+
on mouseUp
40+
repeat with i = 1 to 10 %{AFTER_ENDVALUE} by 10
41+
end repeat
42+
end mouseUp
43+
%EXPECT PASS
44+
%ERROR PE_REPEAT_BADCOND AT AFTER_ENDVALUE
45+
%ENDTEST
46+

0 commit comments

Comments
 (0)