function: Reject invalid variable names for --argument-names

Fixes #6147.
This commit is contained in:
Fabian Homborg 2019-10-07 21:21:38 +02:00
parent 422441e903
commit a7913c3a10
2 changed files with 18 additions and 0 deletions

View File

@ -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 {

View 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