From 56a33a8c558f6b37bf219e289e48cb514cf697fc Mon Sep 17 00:00:00 2001 From: Jason Edmeades Date: Mon, 3 Jun 2013 22:38:15 +0100 Subject: [PATCH] cmd: set "var=value" ignores trailing characters. --- programs/cmd/builtins.c | 19 +++++++++++++++---- programs/cmd/tests/test_builtins.cmd | 18 ++++++++++++++++++ programs/cmd/tests/test_builtins.cmd.exp | 7 +++++++ programs/cmd/wcmd.h | 2 +- programs/cmd/wcmdmain.c | 9 ++++++--- 5 files changed, 47 insertions(+), 8 deletions(-) diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index 3c06e13fd76..c2ccdc86400 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -4038,8 +4038,13 @@ void WCMD_setshow_env (WCHAR *s) { s += 2; while (*s && (*s==' ' || *s=='\t')) s++; - if (*s=='\"') - WCMD_strip_quotes(s); + /* set /P "var=value"jim ignores anything after the last quote */ + if (*s=='\"') { + WCHAR *lastquote; + lastquote = WCMD_strip_quotes(s); + if (lastquote) *lastquote = 0x00; + WINE_TRACE("set: Stripped command line '%s'\n", wine_dbgstr_w(s)); + } /* If no parameter, or no '=' sign, return an error */ if (!(*s) || ((p = strchrW (s, '=')) == NULL )) { @@ -4104,8 +4109,14 @@ void WCMD_setshow_env (WCHAR *s) { } else { DWORD gle; - if (*s=='\"') - WCMD_strip_quotes(s); + /* set "var=value"jim ignores anything after the last quote */ + if (*s=='\"') { + WCHAR *lastquote; + lastquote = WCMD_strip_quotes(s); + if (lastquote) *lastquote = 0x00; + WINE_TRACE("set: Stripped command line '%s'\n", wine_dbgstr_w(s)); + } + p = strchrW (s, '='); if (p == NULL) { env = GetEnvironmentStringsW(); diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd index 45617cff489..48a836268f8 100644 --- a/programs/cmd/tests/test_builtins.cmd +++ b/programs/cmd/tests/test_builtins.cmd @@ -286,6 +286,24 @@ set WINE_FOO=foo@space@ echo '%WINE_FOO%' set WINE_FOO=foo@tab@ echo '%WINE_FOO%' +rem Space symbol must appear in `var` +set WINE_FOO=value@space@ +echo '%WINE_FOO%' +rem Space symbol must NOT appear in `var` +set "WINE_FOO=value"@space@ +echo '%WINE_FOO%' +rem Mixed examples: +set WINE_FOO=jim fred +echo '%WINE_FOO%' +set WINE_FOO="jim" fred +echo '%WINE_FOO%' +set "WINE_FOO=jim fred" +echo '%WINE_FOO%' +set "WINE_FOO=jim" fred +echo '%WINE_FOO%' +rem Only the final quote ends the string +set "WINE_FOO=apple"banana"grape"orange +echo '%WINE_FOO%' set WINE_FOO= echo ------------ Testing variable expansion ------------ diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp index 99ed738bdbb..77e417816bf 100644 --- a/programs/cmd/tests/test_builtins.cmd.exp +++ b/programs/cmd/tests/test_builtins.cmd.exp @@ -251,6 +251,13 @@ foo '' 'foo@space@' 'foo@tab@' +'value@space@' +'value' +'jim fred' +'"jim" fred' +'jim fred' +'jim' +'apple"banana"grape' ------------ Testing variable expansion ------------ ~dp0 should be directory containing batch file @pwd@\ diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h index 418f8c93e77..e5a013842c8 100644 --- a/programs/cmd/wcmd.h +++ b/programs/cmd/wcmd.h @@ -115,7 +115,7 @@ BOOL WCMD_keyword_ws_found(const WCHAR *keyword, int len, const WCHAR *ptr); void WCMD_HandleTildaModifiers(WCHAR **start, BOOL atExecute); void WCMD_splitpath(const WCHAR* path, WCHAR* drv, WCHAR* dir, WCHAR* name, WCHAR* ext); -void WCMD_strip_quotes(WCHAR *cmd); +WCHAR *WCMD_strip_quotes(WCHAR *cmd); WCHAR *WCMD_LoadMessage(UINT id); void WCMD_strsubstW(WCHAR *start, const WCHAR* next, const WCHAR* insert, int len); BOOL WCMD_ReadFile(const HANDLE hIn, WCHAR *intoBuf, const DWORD maxChars, LPDWORD charsRead); diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c index 876bbef8249..0d4575bd9f1 100644 --- a/programs/cmd/wcmdmain.c +++ b/programs/cmd/wcmdmain.c @@ -496,20 +496,23 @@ BOOL WCMD_keyword_ws_found(const WCHAR *keyword, int len, const WCHAR *ptr) { /************************************************************************* * WCMD_strip_quotes * - * Remove first and last quote WCHARacters, preserving all other text + * Remove first and last quote WCHARacters, preserving all other text + * Returns the location of the final quote */ -void WCMD_strip_quotes(WCHAR *cmd) { - WCHAR *src = cmd + 1, *dest = cmd, *lastq = NULL; +WCHAR *WCMD_strip_quotes(WCHAR *cmd) { + WCHAR *src = cmd + 1, *dest = cmd, *lastq = NULL, *lastquote; while((*dest=*src) != '\0') { if (*src=='\"') lastq=dest; dest++, src++; } + lastquote = lastq; if (lastq) { dest=lastq++; while ((*dest++=*lastq++) != 0) ; } + return lastquote; }