cmd: Handle unechoed rem commands inside a (..) section.

When processing a (..) multiline section, each line is processed and
if it starts with a '@' it is not echoed, but more importantly if is
'rem' then anything else on that line should be ignored. The reported
issue was that a pipe was being executed when it was hidden behind a
rem, which was trigged by the preceeding '@' character not being
skipped.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=45729
Signed-off-by: Jason Edmeades <us@edmeades.me.uk>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jason Edmeades 2018-09-10 23:30:20 +01:00 committed by Alexandre Julliard
parent 1a7333bec6
commit f87e25a7bc
3 changed files with 18 additions and 2 deletions

View File

@ -1427,6 +1427,12 @@ for /L %%i in (2,2,1) do (
echo %%i
echo FAILED
)
echo --- rems inside for loops
for /f %%i IN ("hello") DO (
REM foo|echo ERROR unexpected execution 1
@REM foo|echo ERROR unexpected execution 2
@ REM foo|echo ERROR unexpected execution 3
)
echo --- ifs inside for loops
for %%i in (test) do (
echo a1

View File

@ -996,6 +996,7 @@ ErrorLevel 0
-1
1
3
--- rems inside for loops
--- ifs inside for loops
a1
b1

View File

@ -2308,12 +2308,21 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE
} while (*extraData == 0x00);
curPos = extraSpace;
if (context) handleExpansion(extraSpace, FALSE, FALSE);
/* Skip preceding whitespace */
while (*curPos == ' ' || *curPos == '\t') curPos++;
/* Replace env vars if in a batch context */
if (context) handleExpansion(curPos, FALSE, FALSE);
/* Continue to echo commands IF echo is on and in batch program */
if (context && echo_mode && extraSpace[0] && (extraSpace[0] != '@')) {
if (context && echo_mode && *curPos && *curPos != '@') {
WCMD_output_asis(extraSpace);
WCMD_output_asis(newlineW);
}
/* Skip repeated 'no echo' characters and whitespace */
while (*curPos == '@' || *curPos == ' ' || *curPos == '\t') curPos++;
}
}