argparse: Fix validation for short-only-flags

This read something like `o=!_validate_int`, and the flag modifier
reading kept the pointer after the `!`, so it created a long flag
called `_validate_int`, which meant it would not only error out form

```fish
argparse 'i=!_validate_int' 'o=!_validate_int' -- $argv
```

with "Long flag '_validate_int' already defined", but also set
$_flag_validate_int.

Fixes #5864.
This commit is contained in:
Fabian Homborg
2019-05-06 17:24:42 +02:00
parent 5bf21f2928
commit e20c08d04e
4 changed files with 28 additions and 0 deletions

View File

@@ -181,6 +181,8 @@ static bool parse_flag_modifiers(const argparse_cmd_opts_t &opts, const option_s
if (*s == L'!') {
s++;
opt_spec->validation_command = wcstring(s);
// Move cursor to the end so we don't expect a long flag.
while (*s) s++;
} else if (*s) {
streams.err.append_format(BUILTIN_ERR_INVALID_OPT_SPEC, opts.name.c_str(),
option_spec.c_str(), *s);