mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 22:36:03 +08:00
Also catch zero-index errors when indexing into a command substiution
We had previously added a more helpful error message when a literal zero index was specified when indexing into an array. This patch extends that coverage to cases indexing into a command substitution, e.g. ```fish echo (printf "hello\nworld\n")[0] ```
This commit is contained in:
parent
33bc2bc312
commit
c249b1f2f0
|
@ -649,7 +649,12 @@ static expand_result_t expand_cmdsubst(wcstring input, parser_t &parser,
|
|||
|
||||
bad_pos = parse_slice(slice_begin, &slice_end, slice_idx, sub_res.size());
|
||||
if (bad_pos != 0) {
|
||||
append_syntax_error(errors, slice_begin - in + bad_pos, L"Invalid index value");
|
||||
if (tail_begin[bad_pos] == L'0') {
|
||||
append_syntax_error(errors, slice_begin - in + bad_pos,
|
||||
L"array indices start at 1, not 0.");
|
||||
} else {
|
||||
append_syntax_error(errors, slice_begin - in + bad_pos, L"Invalid index value");
|
||||
}
|
||||
return expand_result_t::make_error(STATUS_EXPAND_ERROR);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user