[PATCH 1/1] cmd: Handle lines with just spaces in bracket blocks.
Bernhard Übelacker
wine at gitlab.winehq.org
Sun Jun 19 04:16:23 CDT 2022
From: Bernhard Übelacker <bernhardu at mailbox.org>
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51599
Signed-off-by: Bernhard Übelacker <bernhardu at mailbox.org>
---
programs/cmd/tests/test_builtins.cmd | 4 ++++
programs/cmd/tests/test_builtins.cmd.exp | 1 +
programs/cmd/wcmdmain.c | 18 +++++++++++++++++-
3 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index 3f410e55166..56ef2a5f726 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -1020,6 +1020,10 @@ if not exist %windir% (
) else (
echo windir does exist
)
+if 1 == 0 (
+ echo 1 == 0 should not be true
+ @space@@tab@
+) else echo block containing a line with just spaces seems to work
echo --- case sensitivity with and without /i option
if bar==BAR echo if does not default to case sensitivity
if not bar==BAR echo if seems to default to case sensitivity
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index 8b6e0914112..7ce684ae6fa 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -701,6 +701,7 @@ comparison operators surrounded by brackets seem to work
comparison operators surrounded by brackets seem to work
windir is defined
windir does exist
+block containing a line with just spaces seems to work
--- case sensitivity with and without /i option
if seems to default to case sensitivity
if /i seems to work
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index af54b209d83..1b2f07fdc47 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -1798,6 +1798,22 @@ static BOOL WCMD_IsEndQuote(const WCHAR *quote, int quoteIndex)
return FALSE;
}
+/***************************************************************************
+ * WCMD_isEmptyOrJustWhiteSpace
+ *
+ * Returns TRUE if str is empty or contains just whitespace characters,
+ * otherwise returns FALSE.
+ */
+static BOOL WCMD_isEmptyOrJustWhiteSpace(const WCHAR *str)
+{
+ while (*str != '\0') {
+ if (*str != ' ' && *str != '\t')
+ return FALSE;
+ str++;
+ }
+ return TRUE;
+}
+
/***************************************************************************
* WCMD_ReadAndParseLine
*
@@ -2319,7 +2335,7 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE
} else break;
}
- } while (*extraData == 0x00);
+ } while (WCMD_isEmptyOrJustWhiteSpace(extraData));
curPos = extraSpace;
/* Skip preceding whitespace */
--
GitLab
https://gitlab.winehq.org/wine/wine/-/merge_requests/277
More information about the wine-devel
mailing list