diff --git a/NEWS b/NEWS index 3001529d3..579625365 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,12 @@ For full details, see the git log at: https://github.com/ksh93/ksh Any uppercase BUG_* names are modernish shell bug IDs. +2021-03-17: + +- Fixed a bug with file name completion on the interactive shell in multibyte + locales. Upon encountering two filenames with multibyte characters starting + with the same byte, a partial multibyte character was autocompleted. + 2021-03-16: - Tilde expansion can now be extended or modified by defining a .sh.tilde.get diff --git a/src/cmd/ksh93/edit/completion.c b/src/cmd/ksh93/edit/completion.c index a6086f9a6..f46e7649a 100644 --- a/src/cmd/ksh93/edit/completion.c +++ b/src/cmd/ksh93/edit/completion.c @@ -39,6 +39,7 @@ static char *fmtx(const char *string) int offset = staktell(); if(*cp=='#' || *cp=='~') stakputc('\\'); + mbinit(); while((c=mbchar(cp)),(c>UCHAR_MAX)||(n=state[c])==0 || n==S_EPAT); if(n==S_EOF && *string!='#') return((char*)string); @@ -62,10 +63,18 @@ static int charcmp(int a, int b, int nocase) { if(nocase) { - if(isupper(a)) +#if _lib_towlower + if(mbwide()) + { + a = (int)towlower((wint_t)a); + b = (int)towlower((wint_t)b); + } + else +#endif + { a = tolower(a); - if(isupper(b)) b = tolower(b); + } } return(a==b); } @@ -78,8 +87,10 @@ static int charcmp(int a, int b, int nocase) static char *overlaid(register char *str,register const char *newstr,int nocase) { register int c,d; - while((c= *(unsigned char *)str) && ((d= *(unsigned char*)newstr++),charcmp(c,d,nocase))) - str++; + char *strnext; + mbinit(); + while((strnext = str, c = mbchar(strnext)) && (d = mbchar(newstr), charcmp(c,d,nocase))) + str = strnext; if(*str) *str = 0; else if(*newstr==0) @@ -98,6 +109,7 @@ static char *find_begin(char outbuff[], char *last, int endchar, int *type) int mode=*type; bp = outbuff; *type = 0; + mbinit(); while(cp < last) { xp = cp; @@ -500,6 +512,7 @@ int ed_expand(Edit_t *ep, char outbuff[],int *cur,int *eol,int mode, int count) /* first re-adjust cur */ c = outbuff[*cur]; outbuff[*cur] = 0; + mbinit(); for(out=outbuff; *out;n++) mbchar(out); outbuff[*cur] = c; diff --git a/src/cmd/ksh93/include/version.h b/src/cmd/ksh93/include/version.h index 21edffc0f..6d395d18a 100644 --- a/src/cmd/ksh93/include/version.h +++ b/src/cmd/ksh93/include/version.h @@ -20,7 +20,7 @@ #define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */ #define SH_RELEASE_SVER "1.0.0-alpha" /* semantic version number: https://semver.org */ -#define SH_RELEASE_DATE "2021-03-16" /* must be in this format for $((.sh.version)) */ +#define SH_RELEASE_DATE "2021-03-17" /* must be in this format for $((.sh.version)) */ #define SH_RELEASE_CPYR "(c) 2020-2021 Contributors to ksh " SH_RELEASE_FORK /* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */ diff --git a/src/cmd/ksh93/tests/pty.sh b/src/cmd/ksh93/tests/pty.sh index b5c013482..9e38db763 100755 --- a/src/cmd/ksh93/tests/pty.sh +++ b/src/cmd/ksh93/tests/pty.sh @@ -772,5 +772,18 @@ w echo $? ~\t u 42 /tmp ! +# err_exit # +((SHOPT_MULTIBYTE)) && +[[ ${LC_ALL:-${LC_CTYPE:-${LANG:-}}} =~ [Uu][Tt][Ff]-?8 ]] && +touch $'XXX\xc3\xa1' $'XXX\xc3\xab' && +tst $LINENO <<"!" +L autocomplete should not fill partial multibyte characters +# https://github.com/ksh93/ksh/issues/223 +d 15 +p :test-1: +w : XX\t +r ^:test-1: : XXX\r\n$ +! + # ====== exit $((Errors<125?Errors:125))