1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Fix more spurious comsub execution in tab completion (re: 7a2d3564)

Comsubs were either executed or caused a syntax error when attempting
to complete them within single quotes. Since single quotes do not
expand anything, no such completion should take place.

$ '`/de<TAB>-ksh: /dev/: cannot execute [Is a directory]

$ '$(/de<TAB>-ksh: syntax error: `end of file' unexpected

src/cmd/ksh93/edit/completion.c:
- find_begin():
  - Remove recursive handling for '`' comsubs from 7a2d3564; it is
    sufficient to set the return pointer to the current location cp
    (the character following '`') if we're not in single quotes.
  - For '$' and '`', if we are within single quotes, set type '\''
    and set the return pointer bp to the location of the '$' or
    '`'.
- ed_expand(): If find_begin() sets type '\'' and the current begin
  character is $ or `, refuse to attempt completion; return -1 to
  cause a terminal beep.

Related:
https://github.com/ksh93/ksh/issues/268
https://github.com/ksh93/ksh/issues/462#issuecomment-1038482307
This commit is contained in:
Martijn Dekker 2022-06-06 02:12:33 +01:00
parent d70793d3c0
commit 7a5423dfb6
4 changed files with 40 additions and 7 deletions

View file

@ -135,7 +135,11 @@ static char *find_begin(char outbuff[], char *last, int endchar, int *type)
break;
case '$':
if(inquote == '\'')
{
*type = '\'';
bp = xp;
break;
}
c = *(unsigned char*)cp;
if(mode!='*' && (isaletter(c) || c=='{'))
{
@ -176,11 +180,12 @@ static char *find_begin(char outbuff[], char *last, int endchar, int *type)
break;
case '`':
if(inquote=='\'')
break;
*type = mode;
xp = find_begin(cp,last,'`',type);
if(*(cp=xp)!='`')
{
*type = '\'';
bp = xp;
}
else
bp = cp;
break;
case '=':
if(!inquote)
@ -287,9 +292,15 @@ int ed_expand(Edit_t *ep, char outbuff[],int *cur,int *eol,int mode, int count)
c = *(unsigned char*)out;
var = mode;
begin = out = find_begin(outbuff,last,0,&var);
/* addstar set to zero if * should not be added */
if(var=='$')
if(var=='\'' && (*begin=='$' || *begin=='`'))
{
/* avoid spurious expansion or comsub execution within '...' */
rval = -1;
goto done;
}
else if(var=='$')
{
/* expand ${!varname@} to complete variable name(s) */
stakputs("${!");
stakwrite(out,last-out);
stakputs("@}");
@ -297,6 +308,7 @@ int ed_expand(Edit_t *ep, char outbuff[],int *cur,int *eol,int mode, int count)
}
else
{
/* addstar set to zero if * should not be added */
addstar = '*';
while(out < last)
{