fix to multiple alias expansion problem in command substitutions

This commit is contained in:
Chet Ramey
2022-02-09 10:15:16 -05:00
parent b325b0e96b
commit 780d665cfd
10 changed files with 266 additions and 182 deletions
+14 -11
View File
@@ -313,46 +313,49 @@ 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. Return a new string. */
using backslashes. If FLAGS == 1, also make `unsafe' characters visible by
translating them to a standard ^X/M-X representation (not yet implemented).
Return a new string. */
char *
sh_backslash_quote_for_double_quotes (string, flags)
char *string;
int flags;
{
unsigned char c;
char *result, *r, *s, *send;
size_t slen;
char *result, *send;
size_t slen, sind, rind;
int mb_cur_max;
DECLARE_MBSTATE;
slen = strlen (string);
send = string + slen;
mb_cur_max = MB_CUR_MAX;
result = (char *)xmalloc (2 * slen + 1);
result = (char *)xmalloc ((flags == 1 ? 3 : 2) * slen + 1);
for (r = result, s = string; s && (c = *s); s++)
for (rind = sind = 0; c = string[sind]; sind++)
{
/* Backslash-newline disappears within double quotes, so don't add one. */
if ((sh_syntaxtab[c] & CBSDQUOTE) && c != '\n')
*r++ = '\\';
result[rind++] = '\\';
/* I should probably use the CSPECL flag for these in sh_syntaxtab[] */
else if (c == CTLESC || c == CTLNUL)
*r++ = CTLESC; /* could be '\\'? */
result[rind++] = 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_P (r, s, send);
s--; /* compensate for auto-increment in loop above */
COPY_CHAR_I (result, rind, string, send, sind);
sind--; /* compensate for auto-increment in loop above */
continue;
}
#endif
*r++ = c;
result[rind++] = c;
}
*r = '\0';
result[rind] = '\0';
return (result);
}
#endif /* PROMPT_STRING_DECODE */