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:
parent
d70793d3c0
commit
7a5423dfb6
4 changed files with 40 additions and 7 deletions
6
NEWS
6
NEWS
|
@ -3,6 +3,12 @@ For full details, see the git log at: https://github.com/ksh93/ksh/tree/1.0
|
||||||
|
|
||||||
Any uppercase BUG_* names are modernish shell bug IDs.
|
Any uppercase BUG_* names are modernish shell bug IDs.
|
||||||
|
|
||||||
|
2022-06-05:
|
||||||
|
|
||||||
|
- Fixed a bug where tab completion would spuriously execute a command
|
||||||
|
substitution after entering: '`something<TAB> or generate a spurious
|
||||||
|
'end of file unexpected' syntax error after entering: '$(something<TAB>.
|
||||||
|
|
||||||
2022-06-04:
|
2022-06-04:
|
||||||
|
|
||||||
- Added a new --functrace long-form shell option which causes the -x/--xtrace
|
- Added a new --functrace long-form shell option which causes the -x/--xtrace
|
||||||
|
|
|
@ -135,7 +135,11 @@ static char *find_begin(char outbuff[], char *last, int endchar, int *type)
|
||||||
break;
|
break;
|
||||||
case '$':
|
case '$':
|
||||||
if(inquote == '\'')
|
if(inquote == '\'')
|
||||||
|
{
|
||||||
|
*type = '\'';
|
||||||
|
bp = xp;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
c = *(unsigned char*)cp;
|
c = *(unsigned char*)cp;
|
||||||
if(mode!='*' && (isaletter(c) || c=='{'))
|
if(mode!='*' && (isaletter(c) || c=='{'))
|
||||||
{
|
{
|
||||||
|
@ -176,11 +180,12 @@ static char *find_begin(char outbuff[], char *last, int endchar, int *type)
|
||||||
break;
|
break;
|
||||||
case '`':
|
case '`':
|
||||||
if(inquote=='\'')
|
if(inquote=='\'')
|
||||||
break;
|
{
|
||||||
*type = mode;
|
*type = '\'';
|
||||||
xp = find_begin(cp,last,'`',type);
|
|
||||||
if(*(cp=xp)!='`')
|
|
||||||
bp = xp;
|
bp = xp;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
bp = cp;
|
||||||
break;
|
break;
|
||||||
case '=':
|
case '=':
|
||||||
if(!inquote)
|
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;
|
c = *(unsigned char*)out;
|
||||||
var = mode;
|
var = mode;
|
||||||
begin = out = find_begin(outbuff,last,0,&var);
|
begin = out = find_begin(outbuff,last,0,&var);
|
||||||
/* addstar set to zero if * should not be added */
|
if(var=='\'' && (*begin=='$' || *begin=='`'))
|
||||||
if(var=='$')
|
|
||||||
{
|
{
|
||||||
|
/* avoid spurious expansion or comsub execution within '...' */
|
||||||
|
rval = -1;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
else if(var=='$')
|
||||||
|
{
|
||||||
|
/* expand ${!varname@} to complete variable name(s) */
|
||||||
stakputs("${!");
|
stakputs("${!");
|
||||||
stakwrite(out,last-out);
|
stakwrite(out,last-out);
|
||||||
stakputs("@}");
|
stakputs("@}");
|
||||||
|
@ -297,6 +308,7 @@ int ed_expand(Edit_t *ep, char outbuff[],int *cur,int *eol,int mode, int count)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* addstar set to zero if * should not be added */
|
||||||
addstar = '*';
|
addstar = '*';
|
||||||
while(out < last)
|
while(out < last)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
|
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
|
||||||
#define SH_RELEASE_SVER "1.0.0-beta.2" /* semantic version number: https://semver.org */
|
#define SH_RELEASE_SVER "1.0.0-beta.2" /* semantic version number: https://semver.org */
|
||||||
#define SH_RELEASE_DATE "2022-06-04" /* must be in this format for $((.sh.version)) */
|
#define SH_RELEASE_DATE "2022-06-05" /* must be in this format for $((.sh.version)) */
|
||||||
#define SH_RELEASE_CPYR "(c) 2020-2022 Contributors to ksh " SH_RELEASE_FORK
|
#define SH_RELEASE_CPYR "(c) 2020-2022 Contributors to ksh " SH_RELEASE_FORK
|
||||||
|
|
||||||
/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */
|
/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */
|
||||||
|
|
|
@ -831,6 +831,7 @@ r ^:test-1: test \$\{.sh.level\}\r\n$
|
||||||
((SHOPT_VSH || SHOPT_ESH)) && tst $LINENO <<"!"
|
((SHOPT_VSH || SHOPT_ESH)) && tst $LINENO <<"!"
|
||||||
L tab completion executes command substitutions
|
L tab completion executes command substitutions
|
||||||
# https://github.com/ksh93/ksh/issues/268
|
# https://github.com/ksh93/ksh/issues/268
|
||||||
|
# https://github.com/ksh93/ksh/issues/462#issuecomment-1038482307
|
||||||
|
|
||||||
d 15
|
d 15
|
||||||
p :test-1:
|
p :test-1:
|
||||||
|
@ -839,6 +840,20 @@ r ^:test-1: \$\(echo true\)\r\n$
|
||||||
p :test-2:
|
p :test-2:
|
||||||
w `echo true`\t
|
w `echo true`\t
|
||||||
r ^:test-2: `echo true`\r\n$
|
r ^:test-2: `echo true`\r\n$
|
||||||
|
p :test-3:
|
||||||
|
w '`/dev\t
|
||||||
|
r ^:test-3: '`/dev[[:blank:]]*\r\n$
|
||||||
|
# escape from PS2 prompt with Ctrl+C
|
||||||
|
r ^> $
|
||||||
|
c \cC
|
||||||
|
p :test-4:
|
||||||
|
w '$(/dev\t
|
||||||
|
r ^:test-4: '\$\(/dev[[:blank:]]*\r\n$
|
||||||
|
r ^> $
|
||||||
|
c \cC
|
||||||
|
p :test-5:
|
||||||
|
w $'`/dev\t
|
||||||
|
r ^:test-5: \$'`/dev[[:blank:]]*\r\n$
|
||||||
!
|
!
|
||||||
|
|
||||||
((SHOPT_ESH)) && VISUAL=emacs tst $LINENO <<"!"
|
((SHOPT_ESH)) && VISUAL=emacs tst $LINENO <<"!"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue