From 6809e0599ef57d30f1a3f87f87cd006ea8d589be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Pi=C5=A1l?= Date: Mon, 8 Feb 2021 19:06:43 +0100 Subject: [PATCH] cmd: Fix handling of nested if-for expressions on a single line. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50641 Signed-off-by: Roman Pišl Signed-off-by: Alexandre Julliard --- 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