Commit a5b1172e authored by Jason Edmeades's avatar Jason Edmeades Committed by Alexandre Julliard

cmd: Fix 'for' expansion of wildcards when no args are supplied.

parent 56a33a8c
...@@ -2237,6 +2237,7 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) { ...@@ -2237,6 +2237,7 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
if (!useNumbers && !doFileset) { if (!useNumbers && !doFileset) {
WCHAR fullitem[MAX_PATH]; WCHAR fullitem[MAX_PATH];
int prefixlen = 0;
/* Now build the item to use / search for in the specified directory, /* Now build the item to use / search for in the specified directory,
as it is fully qualified in the /R case */ as it is fully qualified in the /R case */
...@@ -2245,11 +2246,12 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) { ...@@ -2245,11 +2246,12 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
strcatW(fullitem, slashW); strcatW(fullitem, slashW);
strcatW(fullitem, item); strcatW(fullitem, item);
} else { } else {
WCHAR *prefix = strrchrW(item, '\\');
if (prefix) prefixlen = (prefix - item) + 1;
strcpyW(fullitem, item); strcpyW(fullitem, item);
} }
if (strpbrkW (fullitem, wildcards)) { if (strpbrkW (fullitem, wildcards)) {
hff = FindFirstFileW(fullitem, &fd); hff = FindFirstFileW(fullitem, &fd);
if (hff != INVALID_HANDLE_VALUE) { if (hff != INVALID_HANDLE_VALUE) {
do { do {
...@@ -2270,7 +2272,9 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) { ...@@ -2270,7 +2272,9 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
strcatW(fullitem, slashW); strcatW(fullitem, slashW);
strcatW(fullitem, fd.cFileName); strcatW(fullitem, fd.cFileName);
} else { } else {
strcpyW(fullitem, fd.cFileName); if (prefixlen) lstrcpynW(fullitem, item, prefixlen + 1);
fullitem[prefixlen] = 0x00;
strcatW(fullitem, fd.cFileName);
} }
doExecuted = TRUE; doExecuted = TRUE;
......
...@@ -1017,7 +1017,22 @@ for /R %%i in (baz* fred* jim) do call temp.bat %%i ...@@ -1017,7 +1017,22 @@ for /R %%i in (baz* fred* jim) do call temp.bat %%i
call :ValidateExpected call :ValidateExpected
echo for /R passed echo for /R passed
cd .. & rd /s/Q foobar echo --- Complex wildcards unix and windows slash
cd ..
echo Windows slashs, valid path
for %%f in (foobar\baz\bazbaz) do echo ASIS: %%f
for %%f in (foobar\baz\*) do echo WC : %%f
echo Windows slashs, invalid path
for %%f in (foobar\jim\bazbaz) do echo ASIS: %%f
for %%f in (foobar\jim\*) do echo WC : %%f
echo Unix slashs, valid path
for %%f in (foobar/baz/bazbaz) do echo ASIS: %%f
for %%f in (foobar/baz/*) do echo WC : %%f
echo Unix slashs, invalid path
for %%f in (foobar/jim/bazbaz) do echo ASIS: %%f
for %%f in (foobar/jim/*) do echo WC : %%f
echo Done
rd /s/Q foobar
echo --- for /L echo --- for /L
rem Some cases loop forever writing 0s, like e.g. (1,0,1), (1,a,3) or (a,b,c); those can't be tested here rem Some cases loop forever writing 0s, like e.g. (1,0,1), (1,a,3) or (a,b,c); those can't be tested here
for /L %%i in (1,2,0) do echo %%i for /L %%i in (1,2,0) do echo %%i
......
...@@ -691,6 +691,18 @@ Mixed enumeration from provided root ...@@ -691,6 +691,18 @@ Mixed enumeration from provided root
With duplicates enumeration With duplicates enumeration
Strip missing wildcards, keep unwildcarded names Strip missing wildcards, keep unwildcarded names
for /R passed for /R passed
--- Complex wildcards unix and windows slash
Windows slashs, valid path
ASIS: foobar\baz\bazbaz
WC : foobar\baz\bazbaz
Windows slashs, invalid path
ASIS: foobar\jim\bazbaz
Unix slashs, valid path
ASIS: foobar/baz/bazbaz
WC : bazbaz
Unix slashs, invalid path
ASIS: foobar/jim/bazbaz
Done
--- for /L --- for /L
1 1
3 3
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment