diff --git a/std/getopt.d b/std/getopt.d index d1b300374..77a409d0f 100644 --- a/std/getopt.d +++ b/std/getopt.d @@ -582,6 +582,12 @@ private void getoptImpl(T...)(ref string[] args, ref configuration cfg, for (size_t i = 1; i < args.length;) { auto a = args[i]; + if (endOfOptions.length && a == endOfOptions) + { + // Consume the "--" + args = args.remove(i); + break; + } if (!a.length || a[0] != optionChar) { // not an option @@ -589,12 +595,6 @@ private void getoptImpl(T...)(ref string[] args, ref configuration cfg, ++i; continue; } - if (endOfOptions.length && a == endOfOptions) - { - // Consume the "--" - args = args.remove(i); - break; - } if (a == "--help" || a == "-h") { rslt.helpWanted = true; @@ -1304,6 +1304,19 @@ unittest assert(args == ["program", "nonoption", "--option"]); } +// Issue 13317 - std.getopt: endOfOptions broken when it doesn't look like an option +unittest +{ + auto endOfOptionsBackup = endOfOptions; + scope(exit) endOfOptions = endOfOptionsBackup; + endOfOptions = "endofoptions"; + string[] args = ["program", "endofoptions", "--option"]; + bool b = false; + getopt(args, "option", &b); + assert(!b); + assert(args == ["program", "--option"]); +} + /** This function prints the passed $(D Option) and text in an aligned manner. The passed text will be printed first, followed by a newline. Than the short