Jason Edmeades : cmd: Strip quotes from for / f string before attempting to parse it.

Alexandre Julliard julliard at winehq.org
Wed Oct 24 13:39:41 CDT 2012


Module: wine
Branch: master
Commit: a45301cb939f4cfc5a574392c260184d82f35f98
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=a45301cb939f4cfc5a574392c260184d82f35f98

Author: Jason Edmeades <jason at edmeades.me.uk>
Date:   Tue Oct 23 21:35:05 2012 +0100

cmd: Strip quotes from for /f string before attempting to parse it.

---

 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




More information about the wine-cvs mailing list