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

Alexandre Julliard julliard at winehq.org
Wed Feb 10 15:34:02 CST 2021


Module: wine
Branch: master
Commit: 2d6b0b67d91b6433744ec859b10b8ee8eb4a37b3
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=2d6b0b67d91b6433744ec859b10b8ee8eb4a37b3

Author: Roman Pišl <rpisl at seznam.cz>
Date:   Mon Feb  8 19:06:44 2021 +0100

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

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50642
Signed-off-by: Roman Pišl <rpisl at seznam.cz>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 programs/cmd/tests/test_builtins.cmd     | 5 +++++
 programs/cmd/tests/test_builtins.cmd.exp | 2 ++
 programs/cmd/wcmdmain.c                  | 8 +++++++-
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index 4019c51ba73..7cd806c3d54 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -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
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index 129e5313d90..bf5fcddeb9d 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -916,6 +916,8 @@ x at space@
 ---
 ------------ Testing if/for ------------
 A
+------------ Testing if/set ------------
+C:\Program Files (x86)\dummy
 ------------ Testing for ------------
 --- plain FOR
 A
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index fbe8475d8a9..dd7d14e50e5 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -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)) {
 




More information about the wine-cvs mailing list