mirror of
https://github.com/helix-editor/helix.git
synced 2025-01-18 04:57:07 +04:00
Fix slicing panic in path completion variable expansion (#12556)
This commit is contained in:
parent
d4ee22b483
commit
ffdfb59033
@ -103,6 +103,12 @@ fn expand_impl(src: &OsStr, mut resolve: impl FnMut(&OsStr) -> Option<OsString>)
|
||||
let mat = captures.get_match().unwrap();
|
||||
let pattern_id = mat.pattern().as_usize();
|
||||
let mut range = mat.range();
|
||||
// A pattern may match multiple times on a single variable, for example `${HOME:-$HOME}`:
|
||||
// `${HOME:-` matches and also the default value (`$HOME`). Skip past any variables which
|
||||
// have already been expanded.
|
||||
if range.start < pos {
|
||||
continue;
|
||||
}
|
||||
let var = &bytes[captures.get_group(1).unwrap().range()];
|
||||
let default = if pattern_id != 5 {
|
||||
let Some(bracket_pos) = find_brace_end(&bytes[range.end..]) else {
|
||||
@ -203,6 +209,7 @@ fn test_env_expand() {
|
||||
assert_env_expand!(env, "bar/$FOO/baz", "bar/foo/baz");
|
||||
assert_env_expand!(env, "bar/${FOO}/baz", "bar/foo/baz");
|
||||
assert_env_expand!(env, "baz/${BAR:-bar}/foo", "baz/bar/foo");
|
||||
assert_env_expand!(env, "baz/${FOO:-$FOO}/foo", "baz/foo/foo");
|
||||
assert_env_expand!(env, "baz/${BAR:=bar}/foo", "baz/bar/foo");
|
||||
assert_env_expand!(env, "baz/${BAR-bar}/foo", "baz/bar/foo");
|
||||
assert_env_expand!(env, "baz/${BAR=bar}/foo", "baz/bar/foo");
|
||||
|
Loading…
Reference in New Issue
Block a user