[PATCH 7/8] [cmd] Strip quotes from for /f string before attempting to parse it

Ann and Jason Edmeades jason at edmeades.me.uk
Tue Oct 23 16:47:15 CDT 2012


When a string parameter is passed in the quotes need removing before
trying to parse it with the supplied delimiters.

Note the 'fixed' and 'broken' test in the delim= section is purely
a side effect, as delims= values are ignored at the moment.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20121023/c3fcf5c8/attachment-0001.html>
-------------- next part --------------
From c92c667eaa7acbc64225ab8bd1d14dbe557ccfa8 Mon Sep 17 00:00:00 2001
From: Jason Edmeades <jason at edmeades.me.uk>
Date: Tue, 23 Oct 2012 21:35:05 +0100
Subject: [PATCH 7/8] [cmd] Strip quotes from for /f string before attempting
 to parse it

When a string parameter is passed in the quotes need removing before
trying to parse it with the supplied delimiters.

Note the 'fixed' and 'broken' test in the delim= section is purely
a side effect, as delims= values are ignored at the moment.
---
 programs/cmd/builtins.c                  |   12 +++++++++++-
 programs/cmd/tests/test_builtins.cmd     |   11 +++++++++++
 programs/cmd/tests/test_builtins.cmd.exp |   23 ++++++++++++++---------
 3 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 721a1b7..4bb4702 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -2086,8 +2086,18 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
         } else if (doFileset && ((!forf_usebackq && *itemStart == '"') ||
                                  (forf_usebackq && *itemStart == '\''))) {
 
+          /* Remove leading and trailing character, ready to parse with delims= delimiters
+             Note that the last quote is removed from the set and the string terminates
+             there to mimic windows                                                        */
+          WCHAR *strend = strrchrW(itemStart, forf_usebackq?'\'':'"');
+
+          if (strend) {
+            *strend = 0x00;
+            itemStart++;
+          }
+
           /* Copy the item away from the global buffer used by WCMD_parameter */
-          strcpyW(buffer, item);
+          strcpyW(buffer, itemStart);
           WCMD_parse_line(cmdStart, firstCmd, &cmdEnd, variable, buffer, &doExecuted,
                             &forf_skip, forf_eol);
 
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index acd5a44..bfd051b 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -1111,11 +1111,22 @@ set var=
 echo --- for /F
 mkdir foobar & cd foobar
 echo ------ string argument
+rem NT4 does not support usebackq
 for /F %%i in ("a b c") do echo %%i
+for /f usebackq %%i in ('a b c') do echo %%i>output_file
+if not exist output_file (echo no output) else (type output_file & del output_file)
 for /f %%i in ("a ") do echo %%i
+for /f usebackq %%i in ('a ') do echo %%i>output_file
+if not exist output_file (echo no output) else (type output_file & del output_file)
 for /f %%i in ("a") do echo %%i
+for /f usebackq %%i in ('a') do echo %%i>output_file
+if not exist output_file (echo no output) else (type output_file & del output_file)
 fOr /f %%i in (" a") do echo %%i
+for /f usebackq %%i in (' a') do echo %%i>output_file
+if not exist output_file (echo no output) else (type output_file & del output_file)
 for /f %%i in (" a ") do echo %%i
+for /f usebackq %%i in (' a ') do echo %%i>output_file
+if not exist output_file (echo no output) else (type output_file & del output_file)
 echo ------ fileset argument
 echo --------- basic blank handling
 echo a b c>foo
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index 66820be..c15a58d 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -781,11 +781,16 @@ ErrorLevel 0
 
 --- for /F
 ------ string argument
- at todo_wine@a
- at todo_wine@a
 a
- at todo_wine@a
- at todo_wine@a
+a at or_broken@no output
+a
+a at or_broken@no output
+a
+a at or_broken@no output
+a
+a at or_broken@no output
+a
+a at or_broken@no output
 ------ fileset argument
 --------- basic blank handling
 a
@@ -817,18 +822,18 @@ Passed3 at or_broken@Missing functionality - Broken3
 and at or_broken@Broken NT4 functionality1
 Line at or_broken@Broken NT4 functionality2
 Line at or_broken@Broken NT4 functionality3
- at todo_wine@ad
- at todo_wine@z at y
+ad
+z at y
 a|d
- at todo_wine@no output
+no output
 @todo_wine at no output
 ------ delims option
 @todo_wine at a
 @todo_wine at a@space@
 @todo_wine at a d
- at todo_wine@a
+a
 @todo_wine at C r
-foo bar baz
+ at todo_wine@foo bar baz
 @todo_wine at c:\
 ------ skip option
 c
-- 
1.7.9.5


More information about the wine-patches mailing list