Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect behavior of cd ../.foo #46

Merged
merged 1 commit into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ For full details, see the git log at: https://github.com/ksh93/ksh

Any uppercase BUG_* names are modernish shell bug IDs.

2020-06-26:

- Changing to a directory that has a name starting with a '.' will no
longer fail if preceded by '../' (i.e. 'cd ../.local' will now work).

2020-06-24:

- Fixed buggy tab completion of tilde-expanded paths such as
Expand Down
38 changes: 12 additions & 26 deletions src/cmd/ksh93/bltins/cd_pwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,34 +109,20 @@ int b_cd(int argc, char *argv[],Shbltin_t *context)
if(!oldpwd)
oldpwd = path_pwd(shp,1);
}
if(*dir=='.')
if(*dir!='/')
{
/* test for pathname . ./ .. or ../ */
int n=0;
char *sp;
for(dp=dir; *dp=='.'; dp++)
/* check for leading .. */
char *cp;
sfprintf(shp->strbuf,"%s",dir);
cp = sfstruse(shp->strbuf);
pathcanon(cp, 0);
if(cp[0]=='.' && cp[1]=='.' && (cp[2]=='/' || cp[2]==0))
{
if(*++dp=='.' && (*++dp=='/' || *dp==0))
n++;
else if(*dp && *dp!='/')
break;
if(*dp==0)
break;
}
if(n)
{
cdpath = 0;
sp = oldpwd + strlen(oldpwd);
while(n--)
{
while(--sp > oldpwd && *sp!='/');
if(sp==oldpwd)
break;

}
sfwrite(shp->strbuf,oldpwd,sp+1-oldpwd);
sfputr(shp->strbuf,dp,0);
dir = sfstruse(shp->strbuf);
if(!shp->strbuf2)
shp->strbuf2 = sfstropen();
sfprintf(shp->strbuf2,"%s/%s",oldpwd,cp);
dir = sfstruse(shp->strbuf2);
pathcanon(dir, 0);
}
}
rval = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* David Korn <[email protected]> *
* *
***********************************************************************/
#define SH_RELEASE "93u+m 2020-06-24"
#define SH_RELEASE "93u+m 2020-06-26"
9 changes: 9 additions & 0 deletions src/cmd/ksh93/tests/builtins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -717,5 +717,14 @@ chmod is $(whence -p chmod)
chmod is a tracked alias for $(whence -p chmod)"
[[ $actual == $expected ]] || err_exit '`whence -a` does not work correctly with tracked aliases'

# ======
# 'cd ../.foo' should not exclude the '.' in '.foo'
(
cd "$tmp"
mkdir foo .bar
cd foo
cd ../.bar
) || err_exit 'cd ../.bar when ../.bar exists should not fail'

# ======
exit $((Errors<125?Errors:125))