I corrected the code as suggested and added some test cases On Thu, 2011-08-11 at 14:03 +0200, Frédéric Delanoy wrote:
> On Thu, Aug 11, 2011 at 05:19, Nowres Rafid <nowres.ra...@gmail.com> wrote: > > Hello, > > > > the command "cd .. " doesn't work when there is extra spaces at the end. > > > > I propose this patch and ask for your confirmation about it. > > > > best regards. > > } > else { > + > + /* Remove any space at the end of command > + This was because "cd .. " wasn't working */ > + { > + WCHAR *ptr = command + strlenW(command) - 1; > + > + while(*ptr == ' ') > + *ptr-- = 0; > + } > > You shouldn't modify the "command" parameter. This one ought to be > constant, even if it's not currently marked so. > It's better to change the "string" string. > > Also you should add testcases to cmd's test suite, possibly as a > preliminary patch of a series, but it can also be together with the > patch. That's up to you. > > Also for single patches, you don't need "[1/1]"... use git > format-patch "-k" option, or edit the subject before submission. > > Frédéric
>From c75bd914878a2a2e4cfbb6caaa8925b9798c2ab9 Mon Sep 17 00:00:00 2001 From: Nowres Rafid <nowres.ra...@gmail.com> Date: Thu, 11 Aug 2011 13:51:38 +0000 Subject: cmd: fixing an issue with extra whitespaces after cd parameter --- programs/cmd/builtins.c | 8 ++++++- programs/cmd/tests/test_builtins.cmd | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletions(-) diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index 09c166f..1de1987 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -2101,15 +2101,21 @@ void WCMD_setshow_default (WCHAR *command) { WCMD_output (cwd); } else { + pos = string; /* Remove any double quotes, which may be in the middle, eg. cd "C:\Program Files"\Microsoft is ok */ - pos = string; while (*command) { if (*command != '"') *pos++ = *command; command++; } *pos = 0x00; + /* Remove any whitespace at the end of command + This was because "cd .. " wasn't working */ + pos--; + while ( *pos == ' ' || *pos == '\t' ) + *pos-- = 0x00; + /* Search for appropriate directory */ WINE_TRACE("Looking for directory '%s'\n", wine_dbgstr_w(string)); hff = FindFirstFileW(string, &fd); diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd index a83e568..b152787 100644 --- a/programs/cmd/tests/test_builtins.cmd +++ b/programs/cmd/tests/test_builtins.cmd @@ -36,6 +36,45 @@ echo :word echo word@space@ echo word@space@@space@ + +echo ------------ Testing 'cd' -------------- +mkdir test +cd +cd test +cd +cd .. +cd +cd test +cd +cd .. +cd +cd test +cd +cd .. +cd test +cd .. +cd . +cd . +cd test >nul +cd .. >nul +cd testii +mkdir test2 +cd test2 +mkdir test21 +cd test21 +cd ..\.. +cd test2 +mkdir test22 +cd test22 +cd ..\test21 +cd .. +rd test21 +rd test22 +cd .. +rd test +rd test2 + + echo ------------ Testing redirection operators -------------- mkdir foobar & cd foobar echo ...stdout redirection -- 1.7.4.1