From 2a121ef1aa38b3efba8025e2cffe88fb8d69dd9d Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Mon, 6 May 2024 16:54:20 +0200 Subject: [PATCH] function: Check if `--argument-names` gets a valid variable name These were accepted but then ineffective because the only way these are used is to set a variable. --- src/builtins/function.rs | 9 +++++++++ tests/checks/function.fish | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/src/builtins/function.rs b/src/builtins/function.rs index caf9bf64f..95c69c9b0 100644 --- a/src/builtins/function.rs +++ b/src/builtins/function.rs @@ -320,6 +320,15 @@ pub fn function( }) .collect(); + for named in &opts.named_arguments { + if !valid_var_name(&named) { + streams + .err + .append(wgettext_fmt!(BUILTIN_ERR_VARNAME, cmd, named)); + return STATUS_INVALID_ARGS; + } + } + // We have what we need to actually define the function. let props = function::FunctionProperties { func_node, diff --git a/tests/checks/function.fish b/tests/checks/function.fish index 504447950..ca6b88fba 100644 --- a/tests/checks/function.fish +++ b/tests/checks/function.fish @@ -167,4 +167,10 @@ function foo -p bar; end # CHECKERR: function foo -p bar; end # CHECKERR: ^~~~~~~~~~~~~~~~~~~^ +function foo --argument-names "banana pajama"; end +# CHECKERR: {{.*}}function.fish (line {{\d+}}): function: banana pajama: invalid variable name. See `help identifiers` +# CHECKERR: function foo --argument-names "banana pajama"; end +# CHECKERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ + + exit 0