diff --git a/src/builtin_function.cpp b/src/builtin_function.cpp index 94df2c21d..7ba5c9c06 100644 --- a/src/builtin_function.cpp +++ b/src/builtin_function.cpp @@ -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 { diff --git a/tests/checks/function.fish b/tests/checks/function.fish new file mode 100644 index 000000000..51a3b3a32 --- /dev/null +++ b/tests/checks/function.fish @@ -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