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.
This commit is contained in:
Fabian Boehm
2024-05-06 16:54:20 +02:00
parent 39b996332e
commit 2a121ef1aa
2 changed files with 15 additions and 0 deletions

View File

@@ -320,6 +320,15 @@ pub fn function(
}) })
.collect(); .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. // We have what we need to actually define the function.
let props = function::FunctionProperties { let props = function::FunctionProperties {
func_node, func_node,

View File

@@ -167,4 +167,10 @@ function foo -p bar; end
# CHECKERR: function foo -p bar; end # CHECKERR: function foo -p bar; end
# CHECKERR: ^~~~~~~~~~~~~~~~~~~^ # 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 exit 0