mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-31 12:21:19 -03:00
Merge pull request #1630 from kballard/expand_variables_in_quoted_strings
Fix various expansions issues with variables
This commit is contained in:
@@ -617,12 +617,26 @@ static size_t color_variable(const wchar_t *in, size_t in_len, std::vector<highl
|
||||
if (in[idx] == L'[')
|
||||
{
|
||||
wchar_t *slice_begin = NULL, *slice_end = NULL;
|
||||
if (1 == parse_util_locate_slice(in, &slice_begin, &slice_end, false))
|
||||
switch (parse_util_locate_slice(in, &slice_begin, &slice_end, false))
|
||||
{
|
||||
size_t slice_begin_idx = slice_begin - in, slice_end_idx = slice_end - in;
|
||||
assert(slice_end_idx > slice_begin_idx);
|
||||
colors[slice_begin_idx] = highlight_spec_operator;
|
||||
colors[slice_end_idx] = highlight_spec_operator;
|
||||
case 1:
|
||||
{
|
||||
size_t slice_begin_idx = slice_begin - in, slice_end_idx = slice_end - in;
|
||||
assert(slice_end_idx > slice_begin_idx);
|
||||
colors[slice_begin_idx] = highlight_spec_operator;
|
||||
colors[slice_end_idx] = highlight_spec_operator;
|
||||
break;
|
||||
}
|
||||
case -1:
|
||||
{
|
||||
// syntax error
|
||||
// Normally the entire token is colored red for us, but inside a double-quoted string
|
||||
// that doesn't happen. As such, color the variable + the slice start red. Coloring any
|
||||
// more than that looks bad, unless we're willing to try and detect where the double-quoted
|
||||
// string ends, and I'd rather not do that.
|
||||
std::fill(colors, colors + idx + 1, (highlight_spec_t)highlight_spec_error);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return idx;
|
||||
@@ -861,7 +875,11 @@ static void color_argument_internal(const wcstring &buffstr, std::vector<highlig
|
||||
*/
|
||||
case e_double_quoted:
|
||||
{
|
||||
colors[in_pos] = highlight_spec_quote;
|
||||
// slices are colored in advance, past `in_pos`, and we don't want to overwrite that
|
||||
if (colors[in_pos] == highlight_spec_param)
|
||||
{
|
||||
colors[in_pos] = highlight_spec_quote;
|
||||
}
|
||||
switch (c)
|
||||
{
|
||||
case L'"':
|
||||
@@ -876,7 +894,7 @@ static void color_argument_internal(const wcstring &buffstr, std::vector<highlig
|
||||
if (in_pos + 1 < buff_len)
|
||||
{
|
||||
const wchar_t escaped_char = buffstr.at(in_pos + 1);
|
||||
if (escaped_char == L'\\' || escaped_char == L'\'' || escaped_char == L'$')
|
||||
if (wcschr(L"\\\"\n$", escaped_char))
|
||||
{
|
||||
colors[in_pos] = highlight_spec_escape; //backslash
|
||||
colors[in_pos + 1] = highlight_spec_escape; //escaped char
|
||||
|
||||
Reference in New Issue
Block a user