mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-06-30 17:09:50 +02:00
change to how invisible characters in prompt string expansions are escaped
This commit is contained in:
+17
-12
@@ -3330,18 +3330,6 @@ lib/sh/strvis.c
|
||||
- sh_charvis: add a utf-8 locale-specific check before calling
|
||||
COPY_CHAR_I (in practice, doesn't make any real difference)
|
||||
|
||||
lib/sh/shquote.c
|
||||
- sh_backslash_quote_for_double_quotes: if FLAGS&1, call sh_charvis on
|
||||
every character to get the visible representation after possibly
|
||||
adding a quoting backslash
|
||||
|
||||
parse.y
|
||||
- decode_prompt_string: make sure the expansion of \w, \W, and \s
|
||||
are all run through sh_backslash_quote_for_double_quotes with the
|
||||
`make visible' flag or through sh_strvis if we're not running the
|
||||
prompt string through word expansions. Fixes issue reported by
|
||||
Josh Harcome <joshharc@gmail.com> back in mid-January
|
||||
|
||||
3/10
|
||||
----
|
||||
arrayfunc.c
|
||||
@@ -3359,3 +3347,20 @@ jobs.c
|
||||
command for programmable completion. Fixes bug with SIGINT reverting
|
||||
to the saved readline terminal settings reported by
|
||||
Markus Napierkowski <markus.napierkowski@cyberus-technology.de>
|
||||
|
||||
parse.y
|
||||
- decode_prompt_string: make sure the expansion of \w, \W, and \s
|
||||
are all run through sh_strvis before calling
|
||||
sh_backslash_quote_for_double_quotes or just through sh_strvis if
|
||||
we're not running the prompt string through word expansions.
|
||||
Fixes issue reported by Josh Harcome <joshharc@gmail.com> back
|
||||
in mid-January
|
||||
|
||||
3/16
|
||||
----
|
||||
bashline.c
|
||||
- bash_quote_filename: if we have a word to complete that contains
|
||||
characters that introduce a word expansion, make sure the passed
|
||||
string does *not* exist as a filename before removing those
|
||||
characters from the set that must be backslash-quoted. See change
|
||||
from 1/1/2022
|
||||
|
||||
+5
-3
@@ -4288,10 +4288,11 @@ bash_quote_filename (s, rtype, qcp)
|
||||
special to the shell parser). */
|
||||
expchar = nextch = closer = 0;
|
||||
if (*qcp == '\0' && cs == COMPLETE_BSQUOTE && dircomplete_expand == 0 &&
|
||||
(expchar = bash_check_expchar (s, 0, &nextch, &closer)))
|
||||
(expchar = bash_check_expchar (s, 0, &nextch, &closer)) &&
|
||||
file_exists (s) == 0)
|
||||
{
|
||||
/* Usually this will have been set by bash_directory_completion_hook, but
|
||||
there are rare cases where it will not be. */
|
||||
/* Usually this will have been set by bash_directory_completion_hook,
|
||||
but there are cases where it will not be. */
|
||||
if (rl_filename_quote_characters != custom_filename_quote_characters)
|
||||
set_filename_quote_chars (expchar, nextch, closer);
|
||||
complete_fullquote = 0;
|
||||
@@ -4339,6 +4340,7 @@ bash_quote_filename (s, rtype, qcp)
|
||||
|
||||
/* We may need to quote additional characters: those that readline treats
|
||||
as word breaks that are not quoted by backslash_quote. */
|
||||
/* XXX - test complete_fullquote here? */
|
||||
if (rtext && cs == COMPLETE_BSQUOTE)
|
||||
{
|
||||
mtext = quote_word_break_chars (rtext);
|
||||
|
||||
+11
-26
@@ -39,8 +39,6 @@
|
||||
extern char *ansic_quote PARAMS((char *, int, int *));
|
||||
extern int ansic_shouldquote PARAMS((const char *));
|
||||
|
||||
extern int sh_charvis PARAMS((const char *, size_t *, size_t, char *, size_t *));
|
||||
|
||||
/* Default set of characters that should be backslash-quoted in strings */
|
||||
static const char bstab[256] =
|
||||
{
|
||||
@@ -315,59 +313,46 @@ sh_backslash_quote (string, table, flags)
|
||||
|
||||
#if defined (PROMPT_STRING_DECODE) || defined (TRANSLATABLE_STRINGS)
|
||||
/* Quote characters that get special treatment when in double quotes in STRING
|
||||
using backslashes. If FLAGS == 1, also make `unsafe' characters visible by
|
||||
translating them to a standard ^X/M-X representation by calling sh_charvis,
|
||||
which handles multibyte characters as well.
|
||||
Return a new string. */
|
||||
using backslashes. FLAGS is reserved for future use. Return a new string. */
|
||||
char *
|
||||
sh_backslash_quote_for_double_quotes (string, flags)
|
||||
char *string;
|
||||
int flags;
|
||||
{
|
||||
unsigned char c;
|
||||
char *result, *send;
|
||||
size_t slen, sind, rind;
|
||||
char *result, *r, *s, *send;
|
||||
size_t slen;
|
||||
int mb_cur_max;
|
||||
DECLARE_MBSTATE;
|
||||
|
||||
slen = strlen (string);
|
||||
send = string + slen;
|
||||
mb_cur_max = MB_CUR_MAX;
|
||||
/* Max is 4*string length (backslash + three-character visible representation) */
|
||||
result = (char *)xmalloc (4 * slen + 1);
|
||||
result = (char *)xmalloc (2 * slen + 1);
|
||||
|
||||
for (rind = sind = 0; c = string[sind]; sind++)
|
||||
for (r = result, s = string; s && (c = *s); s++)
|
||||
{
|
||||
/* Backslash-newline disappears within double quotes, so don't add one. */
|
||||
|
||||
if ((sh_syntaxtab[c] & CBSDQUOTE) && c != '\n')
|
||||
result[rind++] = '\\';
|
||||
|
||||
if (flags & 1)
|
||||
{
|
||||
sh_charvis (string, &sind, slen, result, &rind);
|
||||
sind--; /* sh_charvis consumes an extra character */
|
||||
continue;
|
||||
}
|
||||
|
||||
*r++ = '\\';
|
||||
/* I should probably use the CSPECL flag for these in sh_syntaxtab[] */
|
||||
else if (c == CTLESC || c == CTLNUL)
|
||||
result[rind++] = CTLESC; /* could be '\\'? */
|
||||
*r++ = CTLESC; /* could be '\\'? */
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if ((locale_utf8locale && (c & 0x80)) ||
|
||||
(locale_utf8locale == 0 && mb_cur_max > 1 && is_basic (c) == 0))
|
||||
{
|
||||
COPY_CHAR_I (result, rind, string, send, sind);
|
||||
sind--; /* compensate for auto-increment in loop above */
|
||||
COPY_CHAR_P (r, s, send);
|
||||
s--; /* compensate for auto-increment in loop above */
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
result[rind++] = c;
|
||||
*r++ = c;
|
||||
}
|
||||
|
||||
result[rind] = '\0';
|
||||
*r = '\0';
|
||||
return (result);
|
||||
}
|
||||
#endif /* PROMPT_STRING_DECODE */
|
||||
|
||||
@@ -5742,7 +5742,12 @@ decode_prompt_string (string)
|
||||
temp = base_pathname (shell_name);
|
||||
/* Try to quote anything the user can set in the file system */
|
||||
if (promptvars || posixly_correct)
|
||||
temp = sh_backslash_quote_for_double_quotes (temp, 1);
|
||||
{
|
||||
char *t;
|
||||
t = sh_strvis (temp);
|
||||
temp = sh_backslash_quote_for_double_quotes (t, 0);
|
||||
free (t);
|
||||
}
|
||||
else
|
||||
temp = sh_strvis (temp);
|
||||
goto add_string;
|
||||
@@ -5819,7 +5824,12 @@ decode_prompt_string (string)
|
||||
/* Make sure that expand_prompt_string is called with a
|
||||
second argument of Q_DOUBLE_QUOTES if we use this
|
||||
function here. */
|
||||
temp = sh_backslash_quote_for_double_quotes (t_string, 1);
|
||||
{
|
||||
char *t;
|
||||
t = sh_strvis (t_string);
|
||||
temp = sh_backslash_quote_for_double_quotes (t, 0);
|
||||
free (t);
|
||||
}
|
||||
else
|
||||
temp = sh_strvis (t_string);
|
||||
|
||||
|
||||
Binary file not shown.
+5
-5
@@ -26,7 +26,7 @@ msgstr ""
|
||||
"Project-Id-Version: bash 5.1\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-11-28 12:51-0500\n"
|
||||
"PO-Revision-Date: 2022-01-12 18:01+0800\n"
|
||||
"PO-Revision-Date: 2022-03-15 23:15+0800\n"
|
||||
"Last-Translator: Wenbin Lv <wenbin816@gmail.com>\n"
|
||||
"Language-Team: Chinese (simplified) <i18n-zh@googlegroups.com>\n"
|
||||
"Language: zh_CN\n"
|
||||
@@ -1437,22 +1437,22 @@ msgstr "不支持网络操作"
|
||||
#: locale.c:217
|
||||
#, c-format
|
||||
msgid "setlocale: LC_ALL: cannot change locale (%s)"
|
||||
msgstr "setlocale: LC_ALL: 无法改变区域选项 (%s)"
|
||||
msgstr "setlocale: LC_ALL: 无法改变区域设置 (%s)"
|
||||
|
||||
#: locale.c:219
|
||||
#, c-format
|
||||
msgid "setlocale: LC_ALL: cannot change locale (%s): %s"
|
||||
msgstr "setlocale: LC_ALL: 无法改变区域选项 (%s):%s"
|
||||
msgstr "setlocale: LC_ALL: 无法改变区域设置 (%s):%s"
|
||||
|
||||
#: locale.c:292
|
||||
#, c-format
|
||||
msgid "setlocale: %s: cannot change locale (%s)"
|
||||
msgstr "setlocale: %s: 无法改变区域选项 (%s)"
|
||||
msgstr "setlocale: %s: 无法改变区域设置 (%s)"
|
||||
|
||||
#: locale.c:294
|
||||
#, c-format
|
||||
msgid "setlocale: %s: cannot change locale (%s): %s"
|
||||
msgstr "setlocale: %s: 无法改变区域选项 (%s):%s"
|
||||
msgstr "setlocale: %s: 无法改变区域设置 (%s):%s"
|
||||
|
||||
#: mailcheck.c:439
|
||||
msgid "You have mail in $_"
|
||||
|
||||
Reference in New Issue
Block a user