mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 13:13:15 +08:00
abbr: Fix crash when no name has been given
This crashed for ```fish abbr --add --regex '{\d+..\d+}' --function foo ``` i.e. a regex and a function but no name - that's 0 additional arguments.
This commit is contained in:
parent
f6f10353be
commit
077118d983
|
@ -202,11 +202,12 @@ static int abbr_add(const abbr_options_t &opts, io_streams_t &streams) {
|
|||
streams.err.append_format(_(L"%ls %ls: Requires at least two arguments\n"), CMD, subcmd);
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
const wcstring &name = opts.args[0];
|
||||
if (name.empty()) {
|
||||
|
||||
if (opts.args.empty() || opts.args[0].empty()) {
|
||||
streams.err.append_format(_(L"%ls %ls: Name cannot be empty\n"), CMD, subcmd);
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
const wcstring &name = opts.args[0];
|
||||
if (std::any_of(name.begin(), name.end(), iswspace)) {
|
||||
streams.err.append_format(
|
||||
_(L"%ls %ls: Abbreviation '%ls' cannot have spaces in the word\n"), CMD, subcmd,
|
||||
|
|
|
@ -194,3 +194,8 @@ abbr --add bogus --position never stuff
|
|||
|
||||
abbr --add bogus --position anywhere --position command stuff
|
||||
# CHECKERR: abbr: Cannot specify multiple positions
|
||||
|
||||
abbr --add --regex foo --function foo
|
||||
# CHECKERR: abbr --add: Name cannot be empty
|
||||
echo foo
|
||||
# CHECK: foo
|
||||
|
|
Loading…
Reference in New Issue
Block a user