diff --git a/src/builtin_argparse.cpp b/src/builtin_argparse.cpp index 1b75a40a4..b6c4405c6 100644 --- a/src/builtin_argparse.cpp +++ b/src/builtin_argparse.cpp @@ -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); diff --git a/tests/argparse.err b/tests/argparse.err index 417c205a0..291e53221 100644 --- a/tests/argparse.err +++ b/tests/argparse.err @@ -121,3 +121,8 @@ in function 'notargparse' #################### # Checking arguments after -- + +#################### +# Checking validation for short flags only +argparse: Value 'banana' for flag 'o' is not an integer +argparse: Value '-o' for flag 'i' is not an integer diff --git a/tests/argparse.in b/tests/argparse.in index 01d9aba3b..444501d7c 100644 --- a/tests/argparse.in +++ b/tests/argparse.in @@ -195,3 +195,12 @@ begin argparse a/alpha -- a --alpha -- b -a printf '%s\n' $argv end + +# #5864 - short flag only with same validation function. +logmsg Checking validation for short flags only +argparse 'i=!_validate_int' 'o=!_validate_int' -- -i 2 -o banana +argparse 'i=!_validate_int' 'o=!_validate_int' -- -i -o banana +begin + argparse 'i=!_validate_int' 'o=!_validate_int' -- -i 2 -o 3 + set -l +end diff --git a/tests/argparse.out b/tests/argparse.out index c70257994..130ae04aa 100644 --- a/tests/argparse.out +++ b/tests/argparse.out @@ -146,3 +146,15 @@ alpha aaaa a b -a + +#################### +# Checking validation for short flags only +_flag_a 'alpha' 'aaaa' +_flag_b -b +_flag_break -b +_flag_i 2 +_flag_m 1 +_flag_max 1 +_flag_o 3 +argv +saved_status 57