>Synopsis:      ksh: tab-completion adds unnecessary trailing "\*" if 
>"~"->$HOME occurred
>Category:      user
>Environment:
        System      : OpenBSD 4.9 (bluesnapper snapshot)
        Details     : OpenBSD 4.9-current (GENERIC) #9: Fri Jul 15 15:35:42 MDT 
2011
                         
[email protected]:/usr/src/sys/arch/i386/compile/GENERIC

        Architecture: OpenBSD.i386
        Machine     : i386
>Description:
On ksh, tab-key completes filenames.
("/home/you/exis<tab>" => "/home/you/existingfile")

Also, tab-key expands "~" to $HOME.
("~/exis<tab>" => "/home/you/existingfile")

If the incomplete filename doesn't match any files,
tab-key does nothing.
("/home/you/nonexis<tab>" =>"/home/you/nonexis")

But, it fails to check the "Not found" case and adds "\*"
to the incomplete filename if the filename contains "~".
("~/nonexis<tab>" => "/home/you/nonexis\*")
This must be a bug.

x_file_glob() (in ksh/edit.c) says it tries to
"Check if globbing failed (returned glob pattern)"
but it checks "(strcmp(words[0], toglob) == 0"
where toglob was only add_glob()'d
while words[0] was also expand(,,DOTILDE)ed.



>How-To-Repeat:
$ cd
$ rm nonexis*
rm: nonexis*: No such file or directory
$ ls ~/nonexis           # press tab

Expected:
$ ls ~/nonexis
or
$ ls /home/you/nonexis

Result:
$ ls /home/you/nonexis\*



>Fix:

Index: edit.c
===================================================================
RCS file: /cvs/src/bin/ksh/edit.c,v
retrieving revision 1.34
diff -p -u -r1.34 edit.c
--- edit.c      20 May 2010 01:13:07 -0000      1.34
+++ edit.c      18 Jul 2011 07:34:19 -0000
@@ -370,6 +370,7 @@ x_file_glob(int flags, const char *str, 
                if (escaping) escaping = 0;
        }
        toglob[idx] = '\0';
+       toglob = substitute(toglob, DOTILDE);
 
        /*
         * Convert "foo*" (toglob) to an array of strings (words)
@@ -385,7 +386,7 @@ x_file_glob(int flags, const char *str, 
        }
        source = sold;
        XPinit(w, 32);
-       expand(yylval.cp, &w, DOGLOB|DOTILDE|DOMARKDIRS);
+       expand(yylval.cp, &w, DOGLOB|DOMARKDIRS);
        XPput(w, NULL);
        words = (char **) XPclose(w);

Reply via email to