Commit 2d6b0b67 authored by Roman Pišl's avatar Roman Pišl Committed by Alexandre Julliard

cmd: Fix handling of brackets in if-set expressions on a single line.

parent 6809e059
......@@ -1246,6 +1246,11 @@ echo ------------ Testing if/for ------------
if ""=="" for %%i in (A) DO (echo %%i)
if not ""=="" for %%i in (B) DO (echo %%i)
echo ------------ Testing if/set ------------
set x=C:\Program Files (x86)
if ""=="" set y=%x%\dummy
echo %y%
echo ------------ Testing for ------------
echo --- plain FOR
for %%i in (A B C) do echo %%i
......
......@@ -916,6 +916,8 @@ x@space@
---
------------ Testing if/for ------------
A
------------ Testing if/set ------------
C:\Program Files (x86)\dummy
------------ Testing for ------------
--- plain FOR
A
......
......@@ -1817,6 +1817,7 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE
static const WCHAR forCmd[] = {'f','o','r'};
static const WCHAR ifCmd[] = {'i','f'};
static const WCHAR ifElse[] = {'e','l','s','e'};
static const WCHAR setCmd[] = {'s','e','t'};
BOOL inOneLine = FALSE;
BOOL inFor = FALSE;
BOOL inIn = FALSE;
......@@ -1829,6 +1830,8 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE
BOOL lastWasElse = FALSE;
BOOL lastWasRedirect = TRUE;
BOOL lastWasCaret = FALSE;
BOOL ignoreBracket = FALSE; /* Some expressions after if (set) require */
/* handling brackets as a normal character */
int lineCurDepth; /* Bracket depth when line was read in */
BOOL resetAtEndOfLine = FALSE; /* Do we need to reset curdepth at EOL */
......@@ -1957,6 +1960,9 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE
curPos+=if_condition_len;
}
if (WCMD_keyword_ws_found(setCmd, ARRAY_SIZE(setCmd), curPos))
ignoreBracket = TRUE;
} else if (WCMD_keyword_ws_found(ifElse, ARRAY_SIZE(ifElse), curPos)) {
const int keyw_len = ARRAY_SIZE(ifElse) + 1;
inElse = TRUE;
......@@ -2146,7 +2152,7 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE
In an ELSE statement, only allow it straight away after
the ELSE and whitespace
*/
} else if (inIf ||
} else if ((inIf && !ignoreBracket) ||
(inElse && lastWasElse && onlyWhiteSpace) ||
(inFor && (lastWasIn || lastWasDo) && onlyWhiteSpace)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment