Skip to content

Commit

Permalink
Tab-completion fixes.
Browse files Browse the repository at this point in the history
* Account for parsecmd() resetting the locale. The locale needs to be
  restored prior to libedit regaining control.
* Do not bother escaping unknown characters that would be taken as
  literal. It is unnecessary and interacts badly with
  --enable-parser-locale: when the parser locale is C, the global
  locale is a multibyte character set, and the text contains any
  multibyte characters when interpreted according to the global
  locale, but invalid bytes when interpreted according to the parser
  locale, escaping each invalid byte renders the resulting string
  invalid in the global locale.
  • Loading branch information
hvdijk committed Aug 6, 2023
1 parent db7d044 commit 322bc1e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/histedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ complete(EditLine *el, int ch)
parsecmd(0);
}

#ifdef WITH_PARSER_LOCALE
/* We were called with the global locale. parsecmd() may have reset to
* the parser locale without getting the chance to restore. Restore it
* now. */
uselocale(LC_GLOBAL_LOCALE);
#endif

if (exception == EXEOF && wordtext && !(wordflags & RT_NOCOMPLETE)) {
char *p;
int flags = EXP_FULL | EXP_TILDE | EXP_COMPLETE;
Expand Down
5 changes: 1 addition & 4 deletions src/mystring.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ shell_quote(const char *s, int style)
fmt = "'\\''";
goto fmt;
}
escape:
*r++ = '\\';
goto output;
}
Expand All @@ -329,10 +328,8 @@ shell_quote(const char *s, int style)
if (c < ' ' || c > '~') {
#endif
#ifdef ENABLE_INTERNAL_COMPLETION
if (style == QS_SINGLE_QUOTED)
if (style > QS_DOLLAR_QUOTED)
goto output;
if (style >= QS_DOUBLE_QUOTED)
goto escape;
#endif
fmt = "\\%03o";
goto fmt;
Expand Down

0 comments on commit 322bc1e

Please sign in to comment.