Module: wine
Branch: stable
Commit: 907c5a2135b2c94f07b251ff51046cb66709c2c9
URL: https://source.winehq.org/git/wine.git/?a=commit;h=907c5a2135b2c94f07b251ff…
Author: Roman Pišl <rpisl(a)seznam.cz>
Date: Mon Feb 8 19:06:43 2021 +0100
cmd: Fix handling of nested if-for expressions on a single line.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50641
Signed-off-by: Roman Pišl <rpisl(a)seznam.cz>
Signed-off-by: Alexandre Julliard <julliard(a)winehq.org>
(cherry picked from commit 6809e0599ef57d30f1a3f87f87cd006ea8d589be)
Signed-off-by: Michael Stefaniuc <mstefani(a)winehq.org>
---
programs/cmd/builtins.c | 10 ++++++++--
programs/cmd/tests/test_builtins.cmd | 4 ++++
programs/cmd/tests/test_builtins.cmd.exp | 2 ++
3 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index e99dd24ac72..0fb40d94e49 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -1599,8 +1599,14 @@ static void WCMD_part_execute(CMD_LIST **cmdList, const WCHAR *firstcmd,
the same bracket depth as the IF, then the IF statement is over. This is required
to handle nested ifs properly */
} else if (isIF && (*cmdList)->bracketDepth == myDepth) {
- WINE_TRACE("Found end of this nested IF statement, ending this if\n");
- break;
+ static const WCHAR doW[] = {'d','o'};
+ if (WCMD_keyword_ws_found(doW, ARRAY_SIZE(doW), (*cmdList)->command)) {
+ WINE_TRACE("Still inside FOR-loop, not an end of IF statement\n");
+ *cmdList = (*cmdList)->nextcommand;
+ } else {
+ WINE_TRACE("Found end of this nested IF statement, ending this if\n");
+ break;
+ }
} else if (!processThese) {
if (curPosition == *cmdList) *cmdList = (*cmdList)->nextcommand;
WINE_TRACE("Skipping this command, as in not process mode (next = %p)\n", *cmdList);
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index c7418b759e4..4019c51ba73 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -1242,6 +1242,10 @@ goto :eof
set WINE_STR_PARMS=
set WINE_INT_PARMS=
+echo ------------ Testing if/for ------------
+if ""=="" for %%i in (A) DO (echo %%i)
+if not ""=="" for %%i in (B) DO (echo %%i)
+
echo ------------ Testing for ------------
echo --- plain FOR
for %%i in (A B C) do echo %%i
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index f75839fdbe8..129e5313d90 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -914,6 +914,8 @@ x@space@
---
x@space@
---
+------------ Testing if/for ------------
+A
------------ Testing for ------------
--- plain FOR
A