mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-10 15:14:44 +00:00
set: Put back zero-index error instead of crashing
This was missed in the initial port in 77aeb6a2a8
.
This commit is contained in:
parent
89ed37d957
commit
d5101e1923
2 changed files with 23 additions and 0 deletions
|
@ -937,6 +937,17 @@ fn set_internal(
|
|||
|
||||
// Setting with explicit indexes like `set foo[3] ...` has additional error handling.
|
||||
if !split.indexes.is_empty() {
|
||||
// Indexes must be > 0. (Note split_var_and_indexes negates negative values).
|
||||
for ind in &split.indexes {
|
||||
if *ind <= 0 {
|
||||
streams.err.append(wgettext_fmt!(
|
||||
"%ls: array index out of bounds\n",
|
||||
cmd
|
||||
));
|
||||
builtin_print_error_trailer(parser, streams.err, cmd);
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
// Append and prepend are disallowed.
|
||||
if opts.append || opts.prepend {
|
||||
streams.err.append(wgettext_fmt!(
|
||||
|
|
|
@ -1001,4 +1001,16 @@ env -u XDG_CONFIG_HOME HOME=$PWD/empty LC_ALL=en_US.UTF-8 $FISH -c 'set -S LC_AL
|
|||
# CHECK: $LC_ALL[1]: |en_US.UTF-8|
|
||||
# CHECK: $LC_ALL: originally inherited as |en_US.UTF-8|
|
||||
|
||||
# This used to crash
|
||||
set line[0] ""
|
||||
# CHECKERR: set: array index out of bounds
|
||||
# CHECKERR: {{.*}}set.fish (line {{\d+}}):
|
||||
# CHECKERR: set line[0] ""
|
||||
# CHECKERR: ^
|
||||
# CHECKERR: (Type 'help set' for related documentation)
|
||||
|
||||
|
||||
echo Still here
|
||||
# CHECK: Still here
|
||||
|
||||
exit 0
|
||||
|
|
Loading…
Reference in a new issue