Module: wine
Branch: stable
Commit: 12242ae0769864cb46881145d6a5f2c70b3f3fea
URL: https://source.winehq.org/git/wine.git/?a=commit;h=12242ae0769864cb46881145…
Author: Jason Edmeades <us(a)edmeades.me.uk>
Date: Mon Sep 10 23:30:20 2018 +0100
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(a)edmeades.me.uk>
Signed-off-by: Alexandre Julliard <julliard(a)winehq.org>
(cherry picked from commit f87e25a7bc2a8917091a9d9d93139bb77eb1e154)
Signed-off-by: Michael Stefaniuc <mstefani(a)winehq.org>
---
programs/cmd/tests/test_builtins.cmd | 6 ++++++
programs/cmd/tests/test_builtins.cmd.exp | 1 +
programs/cmd/wcmdmain.c | 13 +++++++++++--
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index fd63e4e..cf9a986 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -1355,6 +1355,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
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index 30df08a..dd8d1d4 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -981,6 +981,7 @@ ErrorLevel 0
-1
1
3
+--- rems inside for loops
--- ifs inside for loops
a1
b1
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index 5135be4..f1a2679 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -2271,12 +2271,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++;
}
}
Module: wine
Branch: stable
Commit: 8d8445b6209639e75e92d868ac1ec53cb781ac5d
URL: https://source.winehq.org/git/wine.git/?a=commit;h=8d8445b6209639e75e92d868…
Author: Jason Edmeades <us(a)edmeades.me.uk>
Date: Mon Sep 10 23:30:18 2018 +0100
cmd: Handle whitespace in 'for' argument items.
Avoid whitespace affecting the parsing of a for loops items. The
leading and trailing quote or backtick needed removing, and it was
assumed that the trailing character would be that character, which was
wrong when there was whitespace unless the parameter is trimmed.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=45731
Signed-off-by: Jason Edmeades <us(a)edmeades.me.uk>
Signed-off-by: Alexandre Julliard <julliard(a)winehq.org>
(cherry picked from commit becfbb80b4e80680b32cc240b2465e4972590b14)
Signed-off-by: Michael Stefaniuc <mstefani(a)winehq.org>
---
programs/cmd/builtins.c | 8 +++++++-
programs/cmd/tests/test_builtins.cmd | 7 ++++++-
programs/cmd/tests/test_builtins.cmd.exp | 4 ++++
3 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 5d1e1b6..752cf43 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -2061,17 +2061,22 @@ static HANDLE WCMD_forf_getinputhandle(BOOL usebackq, WCHAR *itemstr, BOOL iscmd
WCHAR temp_str[MAX_PATH];
WCHAR temp_file[MAX_PATH];
WCHAR temp_cmd[MAXSTRING];
+ WCHAR *trimmed = NULL;
HANDLE hinput = INVALID_HANDLE_VALUE;
static const WCHAR redirOutW[] = {'>','%','s','\0'};
static const WCHAR cmdW[] = {'C','M','D','\0'};
static const WCHAR cmdslashcW[] = {'C','M','D','.','E','X','E',' ',
'/','C',' ','%','s','\0'};
- /* Remove leading and trailing character */
+ /* Remove leading and trailing character (but there may be trailing whitespace too) */
if ((iscmd && (itemstr[0] == '`' && usebackq)) ||
(iscmd && (itemstr[0] == '\'' && !usebackq)) ||
(!iscmd && (itemstr[0] == '"' && usebackq)))
{
+ trimmed = WCMD_strtrim(itemstr);
+ if (trimmed) {
+ itemstr = trimmed;
+ }
itemstr[strlenW(itemstr)-1] = 0x00;
itemstr++;
}
@@ -2098,6 +2103,7 @@ static HANDLE WCMD_forf_getinputhandle(BOOL usebackq, WCHAR *itemstr, BOOL iscmd
hinput = CreateFileW(itemstr, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
}
+ heap_free(trimmed);
return hinput;
}
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index 1e4997a..fd63e4e 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -1630,8 +1630,11 @@ mkdir foobar & cd foobar
echo ------ string argument
rem NT4 does not support usebackq
for /F %%i in ("a b c") do echo %%i
+for /F %%i in ( "a b c" ) do echo X%%iX
for /f usebackq %%i in ('a b c') do echo %%i>output_file
if not exist output_file (echo no output) else (type output_file & del output_file)
+for /f usebackq %%i in ( 'a b c' ) do echo X%%iX>output_file
+if not exist output_file (echo no output) else (type output_file & del output_file)
for /f %%i in ("a ") do echo %%i
for /f usebackq %%i in ('a ') do echo %%i>output_file
if not exist output_file (echo no output) else (type output_file & del output_file)
@@ -1683,9 +1686,11 @@ for /f "usebackq" %%i in (`echo.Passed2`) do echo %%i
for /f usebackq %%i in (`echo.Passed3`) do echo %%i
for /f "usebackq" %%i in (`"c:\windows\system32\cmd.exe" /C echo Passed4`) do echo %%i
for /f "usebackq" %%i in (`""c:\windows\system32\cmd.exe" /C echo Passed5"`) do echo %%i
+for /f %%i in ( 'echo.Passed6' ) do echo %%i
+for /f "usebackq" %%i in ( `echo.Passed7` ) do echo %%i
goto :ContinueFORF
:SkipFORFcmdNT4
-for /l %%i in (1,1,5) do echo Missing functionality - Broken%%i
+for /l %%i in (1,1,7) do echo Missing functionality - Broken%%i
:ContinueFORF
rem FIXME: Rest not testable right now in wine: not implemented and would need
rem preliminary grep-like program implementation (e.g. like findstr or fc) even
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index a3eca74..30df08a 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -1165,7 +1165,9 @@ WINE_bar correctly 6@or_broken@ERROR: WINE_bar incorrectly 5 [6]
--- for /F
------ string argument
a
+XaX
a@or_broken@no output
+XaX@or_broken@no output
a
a@or_broken@no output
a
@@ -1203,6 +1205,8 @@ Passed2@or_broken@Missing functionality - Broken2
Passed3@or_broken@Missing functionality - Broken3
Passed4@or_broken@Missing functionality - Broken4
Passed5@or_broken@Missing functionality - Broken5
+Passed6@or_broken@Missing functionality - Broken6
+Passed7@or_broken@Missing functionality - Broken7
------ eol option
and@or_broken@Broken NT4 functionality1
Line@or_broken@Broken NT4 functionality2