cmd: set "var=value" ignores trailing characters.

This commit is contained in:
Jason Edmeades 2013-06-03 22:38:15 +01:00 committed by Alexandre Julliard
parent 1648340d09
commit 56a33a8c55
5 changed files with 47 additions and 8 deletions

View file

@ -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();

View file

@ -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 ------------

View file

@ -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@\

View file

@ -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);

View file

@ -497,19 +497,22 @@ 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
* 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;
}