[PATCH v3 0/2] MR277: cmd: Handle lines with just spaces in bracket blocks.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51599 This patch attempts to ignore lines with just spaces inside bracket blocks like it does already for completely empty lines. -- v3: cmd: Avoid execution if block misses closing brackets. cmd: Handle lines with just spaces in bracket blocks. https://gitlab.winehq.org/wine/wine/-/merge_requests/277
From: Bernhard Übelacker <bernhardu(a)mailbox.org> Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51599 --- programs/cmd/tests/test_builtins.cmd | 26 ++++++++++++++++++++++++ programs/cmd/tests/test_builtins.cmd.exp | 6 ++++++ programs/cmd/wcmdmain.c | 1 + 3 files changed, 33 insertions(+) diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd index 510a1ba5931..44dfd080b90 100644 --- a/programs/cmd/tests/test_builtins.cmd +++ b/programs/cmd/tests/test_builtins.cmd @@ -1029,6 +1029,32 @@ if not exist %windir% ( ) else ( echo windir does exist ) +if 1 == 0 ( + echo 1 == 0 should not be true +(a)space@ +) else echo block containing a line with just space seems to work +if 1 == 0 ( + echo 1 == 0 should not be true +(a)tab@ +) else echo block containing a line with just tab seems to work +if 1 == 0 ( + echo 1 == 0 should not be true +(a)space@@tab@ +) else echo block containing a line with just space and tab seems to work +if 1 == 0 ( + echo 1 == 0 should not be true +(a)tab@@space@ +) else echo block containing a line with just tab and space seems to work +if 1 == 0 ( + echo 1 == 0 should not be true +(a)space@ +(a)space@ +) else echo block containing two lines with just space seems to work +if 1 == 0 ( + echo 1 == 0 should not be true +(a)tab@ +(a)tab@ +) else echo block containing two lines with just tab 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 0f48a823109..fc1f9991df4 100644 --- a/programs/cmd/tests/test_builtins.cmd.exp +++ b/programs/cmd/tests/test_builtins.cmd.exp @@ -707,6 +707,12 @@ 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 space seems to work +block containing a line with just tab seems to work +block containing a line with just space and tab seems to work +block containing a line with just tab and space seems to work +block containing two lines with just space seems to work +block containing two lines with just tab 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 843fef8ea50..09cfeae1a01 100644 --- a/programs/cmd/wcmdmain.c +++ b/programs/cmd/wcmdmain.c @@ -2326,6 +2326,7 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE } else break; } + extraData = WCMD_skip_leading_spaces(extraData); } while (*extraData == 0x00); curPos = extraSpace; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/277
From: Bernhard Übelacker <bernhardu(a)mailbox.org> --- programs/cmd/tests/test_builtins.cmd | 24 ++++++++++++++++++++++++ programs/cmd/tests/test_builtins.cmd.exp | 5 +++++ programs/cmd/wcmdmain.c | 7 +++++++ 3 files changed, 36 insertions(+) diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd index 44dfd080b90..1ab2935aec4 100644 --- a/programs/cmd/tests/test_builtins.cmd +++ b/programs/cmd/tests/test_builtins.cmd @@ -1055,6 +1055,30 @@ if 1 == 0 ( @tab@ @tab@ ) else echo block containing two lines with just tab seems to work +:: +echo @if 1 == 1 (> blockclosing.cmd +echo echo with closing bracket>> blockclosing.cmd +echo )>> blockclosing.cmd +cmd.exe /Q /C blockclosing.cmd +echo %ERRORLEVEL% ok +:: +echo @if 1 == 1 (> blockclosing.cmd +echo echo without closing bracket first>> blockclosing.cmd +echo echo without closing bracket second>> blockclosing.cmd +cmd.exe /Q /C blockclosing.cmd +echo %ERRORLEVEL% two lines +:: +echo echo before both blocks> blockclosing.cmd +echo @if 1 == 1 (>> blockclosing.cmd +echo echo before nested block without closing bracket>> blockclosing.cmd +echo @if 2 == 2 (>> blockclosing.cmd +echo echo without closing bracket>> blockclosing.cmd +echo )>> blockclosing.cmd +echo echo outside of block without closing bracket>> blockclosing.cmd +cmd.exe /Q /C blockclosing.cmd +echo %ERRORLEVEL% nested +:: +del blockclosing.cmd 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 fc1f9991df4..0fb4a597ac5 100644 --- a/programs/cmd/tests/test_builtins.cmd.exp +++ b/programs/cmd/tests/test_builtins.cmd.exp @@ -713,6 +713,11 @@ block containing a line with just space and tab seems to work block containing a line with just tab and space seems to work block containing two lines with just space seems to work block containing two lines with just tab seems to work +with closing bracket +0 ok +255 two lines +before both blocks +255 nested --- 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 09cfeae1a01..1867c5afb92 100644 --- a/programs/cmd/wcmdmain.c +++ b/programs/cmd/wcmdmain.c @@ -2347,6 +2347,13 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE } } + if (curDepth > lineCurDepth) { + WINE_TRACE("Brackets do not match, error out without executing.\n"); + WCMD_free_commands(*output); + *output = NULL; + errorlevel = 255; + } + /* Dump out the parsed output */ WCMD_DumpCommands(*output); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/277
Thanks for looking at it. v3: - Drop new function WCMD_isEmptyOrJustWhiteSpace, simply use existing WCMD_skip_leading_spaces - Check if line before unbalanced block gets executed - Drop unneeded carets to create blockclosing.cmd P.S.: Is there a way to maintain visibility of the old patch versions? And is rebasing expected to be done e.g. in two steps, as the "Compare with previous version" contains the rebase too? -- https://gitlab.winehq.org/wine/wine/-/merge_requests/277#note_60751
looks good to me (I get comparions of the whole MR between versions in the 'Changes' thingie; and I don't see how it could be generic enough on a commit by commit basis as, to start with, number of commits in a MR could change between updates) -- https://gitlab.winehq.org/wine/wine/-/merge_requests/277#note_60866
This merge request was approved by eric pouech. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/277
participants (2)
-
Bernhard Übelacker -
eric pouech (@epo)