1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-13 19:52:20 +00:00

Fix buggy completion of ~/some in vi mode (#41)

This commit fixes the bug reported in:
https://github.com/att/ast/issues/682
The following sequence fails in vi mode because ksh looks in the
wrong part of the 'virtual' buffer:

$ touch ~/testfile
$ ls ~/test<tab>

The fix is to change 'virtual[i]' to 'virtual[last_virt]' in the
bugged section of code. The other changes are to make sure listing
files in a directory with something like 'ls /etc/<tab>' calls the
code for Ctrl+L to preserve 'ls /etc/' rather than try (and fail)
to complete the directory name, producing 'ls /etc\n/'. This bugfix
was backported from ksh93v- 2013-10-10-alpha.

src/cmd/ksh93/edit/vi.c
 - Backport the bugfix from ksh93v- 2013-10-10-alpha for this
   problem.

src/cmd/ksh93/tests/pty.sh
 - Add a regression test for this issue using pty, adjusted slightly
   for a fake home directory in /tmp.
This commit is contained in:
Johnothan King 2020-06-25 14:08:43 -07:00 committed by Martijn Dekker
parent d41ec674c7
commit 4cecde1dd3
4 changed files with 30 additions and 4 deletions

5
NEWS
View file

@ -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-24:
- Fixed buggy tab completion of tilde-expanded paths such as
~/some in 'vi' mode.
2020-06-23:
- Fixed a bug that caused combining process substitution with redirection

View file

@ -2391,6 +2391,7 @@ static int textmod(register Vi_t *vp,register int c, int mode)
register genchar *p = vp->lastline;
register int trepeat = vp->repeat;
genchar *savep;
int ch;
if(mode && (fold(vp->lastmotion)=='F' || fold(vp->lastmotion)=='T'))
vp->lastmotion = ';';
@ -2421,7 +2422,10 @@ addin:
++last_virt;
mode = cur_virt-1;
virtual[last_virt] = 0;
if(ed_expand(vp->ed,(char*)virtual, &cur_virt, &last_virt, c, vp->repeat_set?vp->repeat:-1)<0)
ch = c;
if(mode>=0 && c=='\\' && virtual[mode+1]=='/')
c = '=';
if(ed_expand(vp->ed,(char*)virtual, &cur_virt, &last_virt, ch, vp->repeat_set?vp->repeat:-1)<0)
{
if(vp->ed->e_tabcount)
{
@ -2433,9 +2437,8 @@ addin:
last_virt = i;
ed_ringbell();
}
else if((c=='=' || (c=='\\'&&virtual[i]=='/')) && !vp->repeat_set)
else if((c=='=' || (c=='\\'&&virtual[last_virt]=='/')) && !vp->repeat_set)
{
last_virt = i;
vp->nonewline++;
ed_ungetchar(vp->ed,cntl('L'));
return(GOOD);

View file

@ -17,4 +17,4 @@
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#define SH_RELEASE "93u+m 2020-06-23"
#define SH_RELEASE "93u+m 2020-06-24"

View file

@ -453,4 +453,22 @@ w fg
u yes-yes
!
# ======
# err_exit #
# Test file name completion in vi mode
mkdir /tmp/fakehome
tst $LINENO <<"!"
L vi mode file name completion
# Completing a file name in vi mode that contains '~' and has a
# base name the same length as the home directory's parent directory
# shouldn't fail.
w set -o vi; HOME=/tmp/fakehome; touch ~/testfile
w echo ~/tes\t
u ^/tmp/fakehome/testfile\r?\n$
!
rm -r /tmp/fakehome
# ======
exit $((Errors<125?Errors:125))