From c249b1f2f057b53dd169779497f3eeae1447ca68 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Tue, 7 Apr 2020 20:02:40 -0500 Subject: [PATCH] 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] ``` --- src/expand.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/expand.cpp b/src/expand.cpp index 396745476..4473b481f 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -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); }