[PATCH 3/5] cmd: improve parsing of quotes in command line
Martin Wilck
mwilck at arcor.de
Wed Sep 28 17:46:36 CDT 2011
Fix parsing of quotes inside words (f"oo b"ar, two" "words) in
the CMD.EXE command line.
---
programs/cmd/tests/test_cmdline.cmd.exp | 24 ++++++++++++------------
programs/cmd/wcmdmain.c | 24 +++++++++++++++---------
2 files changed, 27 insertions(+), 21 deletions(-)
diff --git a/programs/cmd/tests/test_cmdline.cmd.exp b/programs/cmd/tests/test_cmdline.cmd.exp
index de8d575..6d5805a 100755
--- a/programs/cmd/tests/test_cmdline.cmd.exp
+++ b/programs/cmd/tests/test_cmdline.cmd.exp
@@ -1,37 +1,37 @@
------ Testing invocation of batch files ----------
0 at space@
1 at space@
- at todo_wine@1 at space@
1 at space@
- at todo_wine@1 at space@
+1 at space@
+1 at space@
0 at space@
- at todo_wine@1 at space@
- at todo_wine@2 at space@
+1 at space@
+2 at space@
0 at space@
3 at space@
- at todo_wine@3 at space@
+3 at space@
@todo_wine at 4@space@
------ Testing invocation with CMD /C -------------
0 at space@
1 at space@
- at todo_wine@0 at space@
0 at space@
- at todo_wine@1 at space@
0 at space@
- at todo_wine@1 at space@
- at todo_wine@2 at space@
+1 at space@
+0 at space@
+1 at space@
+2 at space@
0 at space@
- at todo_wine@3 at space@
+3 at space@
@todo_wine at 4@space@
---------- Testing CMD /C quoting -----------------
"hi"
- at todo_wine@1 at space@
+1 at space@
"\"\\"\\\"\\\\"@space@"\"\\"\\\"\\\\"
1 at space@
0 at space@
1 at space@
0 at space@
- at todo_wine@0 at space@
+0 at space@
0 at space@@or_broken at 3@space@
3 at space@
2 at space@
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index 78416ac..16ffe30 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -907,6 +907,10 @@ static void WCMD_parse (const WCHAR *s, WCHAR *q, WCHAR *p1, WCHAR *p2)
*q = *p1 = *p2 = '\0';
while (TRUE) {
switch (*s) {
+ case '\0':
+ if (p == 0) *p1 = '\0';
+ if (p == 1) *p2 = '\0';
+ return;
case '/':
*q++ = *s++;
while ((*s != '\0') && (*s != ' ') && *s != '/') {
@@ -925,20 +929,21 @@ static void WCMD_parse (const WCHAR *s, WCHAR *q, WCHAR *p1, WCHAR *p2)
else if (p == 1) *p2++ = *s++;
else s++;
}
- if (p == 0) *p1 = '\0';
- if (p == 1) *p2 = '\0';
- p++;
- if (*s == '"') s++;
- break;
- case '\0':
- return;
+ if (*s == '\0')
+ break;
+ s++;
+ /* closing quote - parameter ends only if followed by whitespace */
+ /* fall through to default case */
default:
while ((*s != '\0') && (*s != ' ') && (*s != '\t')
- && (*s != '=') && (*s != ',') ) {
+ && (*s != '=') && (*s != ',') && (*s != '"')) {
if (p == 0) *p1++ = *s++;
else if (p == 1) *p2++ = *s++;
else s++;
}
+ if (*s == '"')
+ /* opening quote - go back to '"' case */
+ break;
/* Skip concurrent parms */
while ((*s == ' ') || (*s == '\t') || (*s == '=') || (*s == ',') ) s++;
@@ -1460,7 +1465,8 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
*/
count = 0;
- while (IsCharAlphaNumericW(whichcmd[count])) {
+ /* 'echo" one"' is not 'echo one' */
+ while (IsCharAlphaNumericW(whichcmd[count]) || whichcmd[count] == '"') {
count++;
}
for (i=0; i<=WCMD_EXIT; i++) {
--
1.7.3.4
More information about the wine-patches
mailing list