function: Reject invalid variable names for --argument-names
Fixes #6147.
This commit is contained in:
parent
422441e903
commit
a7913c3a10
@ -225,6 +225,10 @@ int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_lis
|
||||
if (argc != optind) {
|
||||
if (opts.named_arguments.size()) {
|
||||
for (int i = optind; i < argc; i++) {
|
||||
if (!valid_var_name(argv[i])) {
|
||||
streams.err.append_format(BUILTIN_ERR_VARNAME, cmd, argv[i]);
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
opts.named_arguments.push_back(argv[i]);
|
||||
}
|
||||
} else {
|
||||
|
14
tests/checks/function.fish
Normal file
14
tests/checks/function.fish
Normal file
@ -0,0 +1,14 @@
|
||||
#RUN: %fish %s
|
||||
function t --argument-names a b c
|
||||
echo t
|
||||
end
|
||||
|
||||
function t2 --argument-names a b c --no-scope-shadowing
|
||||
echo t2
|
||||
end
|
||||
#CHECKERR: function.fish (line {{\d+}}): function: Variable name '--no-scope-shadowing' is not valid. See `help identifiers`.
|
||||
#CHECKERR: function t2 --argument-names a b c --no-scope-shadowing
|
||||
#CHECKERR: ^
|
||||
|
||||
functions -q t2 && echo exists || echo does not exist
|
||||
#CHECK: does not exist
|
Loading…
x
Reference in New Issue
Block a user