From 220c3b9a9e06f51143e2d8d736466d55fdd5e340 Mon Sep 17 00:00:00 2001 From: Jaroslav Mracek Date: Mon, 22 Apr 2024 12:03:10 +0200 Subject: [PATCH] Raise an exception when `=` is used with short option It prevents silently skipping the change in behavior between DNF4 and DNF5 Where `-x=dnf` excluded `dnf` but in DNF5 it excludes `=dnf`. Without the exception it would be hard to detect that something might work differently then expected. Closes: https://github.com/rpm-software-management/dnf5/issues/1353 --- libdnf5-cli/argument_parser.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libdnf5-cli/argument_parser.cpp b/libdnf5-cli/argument_parser.cpp index 1ba51a62e..d39d39c8a 100644 --- a/libdnf5-cli/argument_parser.cpp +++ b/libdnf5-cli/argument_parser.cpp @@ -553,15 +553,18 @@ int ArgumentParser::NamedArg::parse_short(const char * option, int argc, const c const char * arg_value; int consumed_args; if (has_value) { - if (option[1] != '\0') { - arg_value = option + 1; - consumed_args = 1; - } else { + if (option[1] == '\0') { if (argc < 2) { throw ArgumentParserNamedArgMissingValueError(M_("Missing value for named argument \"-{}\""), *option); } arg_value = argv[1]; consumed_args = 2; + } else if (option[1] == '=') { + throw ArgumentParserInvalidValueError( + M_("'=' is not supported delimiter for short option \"-{}\""), std::string(option)); + } else { + arg_value = option + 1; + consumed_args = 1; } } else { arg_value = const_val.c_str();