Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions std/getopt.d
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ private bool handleOption(R)(string option, R receiver, ref string[] args,
enum isCallbackWithLessThanTwoParameters =
(is(R == delegate) || is(Target == function)) &&
!is(typeof(receiver("", "")));
if (!isCallbackWithLessThanTwoParameters && !(val.length) && !incremental)
if (!isCallbackWithLessThanTwoParameters && val is null && !incremental)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this breaks a unittest (at line 1036), presumably either it needs updating or we need to check for both val is null && !(val.length)

{
// Eat the next argument too. Check to make sure there's one
// to be eaten first, though.
Expand Down Expand Up @@ -1192,7 +1192,7 @@ private bool optMatch(string arg, scope string optPattern, ref string value,
if (!isLong && !cfg.bundling)
{
// argument looks like -ovalue and there's no bundling
value = arg[1 .. $];
value = arg.length > 1 ? arg[1 .. $] : null;
arg = arg[0 .. 1];
}
else
Expand Down Expand Up @@ -2050,3 +2050,14 @@ void defaultGetoptFormatter(Output)(Output output, string text, Option[] opt, st
getopt(args, "foo|f", &a);
assert(a == 1337);
}

// https://github.com/dlang/phobos/issues/10791
@safe unittest
{
string arg1, arg2;

auto args = ["prog", "--arg1=", "--arg2=p2"];
getopt(args, "arg1", &arg1, "arg2", &arg2);
assert(arg1 == "", "arg1 should be empty string, got: " ~ arg1);
assert(arg2 == "p2");
}
Loading