mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
Fix for parse_util_token_extent doing the wrong thing inside a command
substitution. Fixes https://github.com/fish-shell/fish-shell/issues/833
This commit is contained in:
parent
44bd405ed3
commit
97ea61a407
2 changed files with 18 additions and 19 deletions
|
@ -411,35 +411,34 @@ void parse_util_token_extent(const wchar_t *buff,
|
|||
const wchar_t **prev_begin,
|
||||
const wchar_t **prev_end)
|
||||
{
|
||||
const wchar_t *begin, *end;
|
||||
long pos;
|
||||
|
||||
const wchar_t *a = NULL, *b = NULL, *pa = NULL, *pb = NULL;
|
||||
|
||||
CHECK(buff,);
|
||||
|
||||
assert(cursor_pos >= 0);
|
||||
|
||||
parse_util_cmdsubst_extent(buff, cursor_pos, &begin, &end);
|
||||
const wchar_t *cmdsubst_begin, *cmdsubst_end;
|
||||
parse_util_cmdsubst_extent(buff, cursor_pos, &cmdsubst_begin, &cmdsubst_end);
|
||||
|
||||
if (!end || !begin)
|
||||
if (!cmdsubst_end || !cmdsubst_begin)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pos = cursor_pos - (begin - buff);
|
||||
/* pos is equivalent to cursor_pos within the range of the command substitution {begin, end} */
|
||||
long offset_within_cmdsubst = cursor_pos - (cmdsubst_begin - buff);
|
||||
|
||||
a = buff + pos;
|
||||
a = cmdsubst_begin + offset_within_cmdsubst;
|
||||
b = a;
|
||||
pa = buff + pos;
|
||||
pa = cmdsubst_begin + offset_within_cmdsubst;
|
||||
pb = pa;
|
||||
|
||||
assert(begin >= buff);
|
||||
assert(begin <= (buff+wcslen(buff)));
|
||||
assert(end >= begin);
|
||||
assert(end <= (buff+wcslen(buff)));
|
||||
assert(cmdsubst_begin >= buff);
|
||||
assert(cmdsubst_begin <= (buff+wcslen(buff)));
|
||||
assert(cmdsubst_end >= cmdsubst_begin);
|
||||
assert(cmdsubst_end <= (buff+wcslen(buff)));
|
||||
|
||||
const wcstring buffcpy = wcstring(begin, end-begin);
|
||||
const wcstring buffcpy = wcstring(cmdsubst_begin, cmdsubst_end-cmdsubst_begin);
|
||||
|
||||
tokenizer_t tok(buffcpy.c_str(), TOK_ACCEPT_UNFINISHED | TOK_SQUASH_ERRORS);
|
||||
for (; tok_has_next(&tok); tok_next(&tok))
|
||||
|
@ -460,9 +459,9 @@ void parse_util_token_extent(const wchar_t *buff,
|
|||
cursor is between two tokens, so we set it to a zero element
|
||||
string and break
|
||||
*/
|
||||
if (tok_begin > pos)
|
||||
if (tok_begin > offset_within_cmdsubst)
|
||||
{
|
||||
a = b = (wchar_t *)buff + pos;
|
||||
a = b = cmdsubst_begin + offset_within_cmdsubst;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -470,9 +469,9 @@ void parse_util_token_extent(const wchar_t *buff,
|
|||
If cursor is inside the token, this is the token we are
|
||||
looking for. If so, set a and b and break
|
||||
*/
|
||||
if ((tok_last_type(&tok) == TOK_STRING) && (tok_end >= pos))
|
||||
if ((tok_last_type(&tok) == TOK_STRING) && (tok_end >= offset_within_cmdsubst))
|
||||
{
|
||||
a = begin + tok_get_pos(&tok);
|
||||
a = cmdsubst_begin + tok_get_pos(&tok);
|
||||
b = a + wcslen(tok_last(&tok));
|
||||
break;
|
||||
}
|
||||
|
@ -482,7 +481,7 @@ void parse_util_token_extent(const wchar_t *buff,
|
|||
*/
|
||||
if (tok_last_type(&tok) == TOK_STRING)
|
||||
{
|
||||
pa = begin + tok_get_pos(&tok);
|
||||
pa = cmdsubst_begin + tok_get_pos(&tok);
|
||||
pb = pa + wcslen(tok_last(&tok));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2170,7 +2170,7 @@ static void reader_replace_current_token(const wchar_t *new_token)
|
|||
|
||||
/* Find current token */
|
||||
const wchar_t *buff = data->command_line.c_str();
|
||||
parse_util_token_extent((wchar_t *)buff, data->buff_pos, &begin, &end, 0, 0);
|
||||
parse_util_token_extent(buff, data->buff_pos, &begin, &end, 0, 0);
|
||||
|
||||
if (!begin || !end)
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue