Reader: Fix crash completing incomplete variable name

Regression in 4.1, not present in 4.0.

Fixes #11148
This commit is contained in:
Fabian Boehm
2025-02-11 22:13:38 +01:00
parent 7accf4ffa1
commit 3350145371

View File

@@ -6057,19 +6057,20 @@ pub fn completion_apply_to_command_line(
escape_flags.insert(EscapeFlags::NO_TILDE);
}
let maybe_add_slash = |trailer: &mut char, token: &wstr| {
let maybe_slash = |trailer: Option<char>, token: &wstr| -> Option<char> {
let mut expanded = token.to_owned();
if expand_one(&mut expanded, ExpandFlags::FAIL_ON_CMDSUBST, ctx, None)
&& wstat(&expanded).is_ok_and(|md| md.is_dir())
{
*trailer = '/';
return Some('/');
}
trailer
};
if do_replace_token {
if is_variable_name {
assert!(!do_escape);
maybe_add_slash(trailer.as_mut().unwrap(), val_str);
trailer = maybe_slash(trailer, val_str);
}
let mut move_cursor = 0;
let (range, _) = parse_util_token_extent(command_line, cursor_pos);
@@ -6152,7 +6153,7 @@ pub fn completion_apply_to_command_line(
if let Some(mut trailer) = trailer {
if is_variable_name {
let (tok, _) = parse_util_token_extent(command_line, cursor_pos);
maybe_add_slash(&mut trailer, &result[tok.start..new_cursor_pos]);
trailer = maybe_slash(Some(trailer), &result[tok.start..new_cursor_pos]).unwrap();
}
if trailer != '/'
&& quote.is_some()