mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-14 00:47:30 +00:00
Return 1 if non-existent field is given
This commit is contained in:
parent
1329a40e87
commit
21bbd2ecb4
2 changed files with 7 additions and 4 deletions
|
@ -1175,10 +1175,13 @@ static int string_split_maybe0(parser_t &parser, io_streams_t &streams, int argc
|
|||
if (opts.fields.size() > 0) {
|
||||
for (const auto &field : opts.fields) {
|
||||
// field indexing starts from 1
|
||||
if (field - 1 < (long)split_count) {
|
||||
buff.append(splits.at(field - 1), separation_type_t::explicitly);
|
||||
if (field - 1 >= (long)split_count) {
|
||||
return STATUS_CMD_ERROR;
|
||||
}
|
||||
}
|
||||
for (const auto &field : opts.fields) {
|
||||
buff.append(splits.at(field - 1), separation_type_t::explicitly);
|
||||
}
|
||||
} else {
|
||||
for (const wcstring &split : splits) {
|
||||
buff.append(split, separation_type_t::explicitly);
|
||||
|
|
|
@ -95,8 +95,8 @@ string split --fields=3,2 "" abc
|
|||
# CHECK: c
|
||||
# CHECK: b
|
||||
|
||||
string split --fields=2,9 "" abc
|
||||
# CHECK: b
|
||||
string split --fields=2,9 "" abc; or echo "exit 1"
|
||||
# CHECK: exit 1
|
||||
|
||||
string split --fields=1-3,5,9-7 "" 123456789
|
||||
# CHECK: 1
|
||||
|
|
Loading…
Reference in a new issue