mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 21:44:16 +00:00
Fix for crashing and assertion failures when tab completing a token that consists of only backslash
Fixes https://github.com/fish-shell/fish-shell/issues/762
This commit is contained in:
parent
f8786c25be
commit
924b646b79
1 changed files with 10 additions and 8 deletions
18
reader.cpp
18
reader.cpp
|
@ -3043,17 +3043,25 @@ const wchar_t *reader_readline(void)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Either the user hit tab only once, or we had no visible completion list. */
|
/* Either the user hit tab only once, or we had no visible completion list. */
|
||||||
const wchar_t *cmdsub_begin, *cmdsub_end;
|
|
||||||
const wchar_t *token_begin, *token_end;
|
/* Remove a trailing backslash. This may trigger an extra repaint, but this is rare. */
|
||||||
|
if (is_backslashed(data->command_line, data->buff_pos))
|
||||||
|
{
|
||||||
|
remove_backward();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the string; we have to do this after removing any trailing backslash */
|
||||||
const wchar_t * const buff = data->command_line.c_str();
|
const wchar_t * const buff = data->command_line.c_str();
|
||||||
|
|
||||||
/* Clear the completion list */
|
/* Clear the completion list */
|
||||||
comp.clear();
|
comp.clear();
|
||||||
|
|
||||||
/* Figure out the extent of the command substitution surrounding the cursor. This is because we only look at the current command substitution to form completions - stuff happening outside of it is not interesting. */
|
/* Figure out the extent of the command substitution surrounding the cursor. This is because we only look at the current command substitution to form completions - stuff happening outside of it is not interesting. */
|
||||||
|
const wchar_t *cmdsub_begin, *cmdsub_end;
|
||||||
parse_util_cmdsubst_extent(buff, data->buff_pos, &cmdsub_begin, &cmdsub_end);
|
parse_util_cmdsubst_extent(buff, data->buff_pos, &cmdsub_begin, &cmdsub_end);
|
||||||
|
|
||||||
/* Figure out the extent of the token within the command substitution. Note we pass cmdsub_begin here, not buff */
|
/* Figure out the extent of the token within the command substitution. Note we pass cmdsub_begin here, not buff */
|
||||||
|
const wchar_t *token_begin, *token_end;
|
||||||
parse_util_token_extent(cmdsub_begin, data->buff_pos - (cmdsub_begin-buff), &token_begin, &token_end, 0, 0);
|
parse_util_token_extent(cmdsub_begin, data->buff_pos - (cmdsub_begin-buff), &token_begin, &token_end, 0, 0);
|
||||||
|
|
||||||
/* Figure out how many steps to get from the current position to the end of the current token. */
|
/* Figure out how many steps to get from the current position to the end of the current token. */
|
||||||
|
@ -3066,12 +3074,6 @@ const wchar_t *reader_readline(void)
|
||||||
reader_repaint();
|
reader_repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove a trailing backslash. This may trigger an extra repaint, but this is rare. */
|
|
||||||
if (is_backslashed(data->command_line, data->buff_pos))
|
|
||||||
{
|
|
||||||
remove_backward();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Construct a copy of the string from the beginning of the command substitution up to the end of the token we're completing */
|
/* Construct a copy of the string from the beginning of the command substitution up to the end of the token we're completing */
|
||||||
const wcstring buffcpy = wcstring(cmdsub_begin, token_end);
|
const wcstring buffcpy = wcstring(cmdsub_begin, token_end);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue