diff --git a/src/shared/options.c b/src/shared/options.c index 09b677f813..903ed62440 100644 --- a/src/shared/options.c +++ b/src/shared/options.c @@ -112,8 +112,10 @@ int option_parse( return 0; } - if (!state->parsing_stopped && - argv[state->optind][0] == '-' && + if (state->parsing_stopped) + return 0; + + if (argv[state->optind][0] == '-' && argv[state->optind][1] != '\0') /* Looks like we found an option parameter */ break; diff --git a/src/test/test-options.c b/src/test/test-options.c index 6ca29fb849..ab3a429369 100644 --- a/src/test/test-options.c +++ b/src/test/test-options.c @@ -977,6 +977,21 @@ TEST(option_macros) { NULL); /* OPTION_STOPS_PARSING then "--": "--" is still consumed after exec */ + test_macros_parse_one(STRV_MAKE("arg0", + "--help", + "--exec", + "--", + "--version", + "-h"), + (Entry[]) { + { "help" }, + { "exec" }, + {} + }, + STRV_MAKE("--version", + "-h")); + + /* OPTION_STOPS_PARSING then later "--": "--" is not consumed */ test_macros_parse_one(STRV_MAKE("arg0", "--help", "--exec", @@ -989,6 +1004,24 @@ TEST(option_macros) { {} }, STRV_MAKE("--version", + "--", + "-h")); + + /* OPTION_STOPS_PARSING then "--" twice: second "--" is not consumed */ + test_macros_parse_one(STRV_MAKE("arg0", + "--help", + "--exec", + "--", + "--", + "--version", + "-h"), + (Entry[]) { + { "help" }, + { "exec" }, + {} + }, + STRV_MAKE("--", + "--version", "-h")); }