Skip to content

Commit

Permalink
Merge pull request #5525 from Hackerpilot/issue-17574
Browse files Browse the repository at this point in the history
Fix issue 17574 - Avoid range error by checking the result of indexOf
merged-on-behalf-of: H. S. Teoh <[email protected]>
  • Loading branch information
dlang-bot authored Jun 30, 2017
2 parents e37ce5a + 59108e6 commit 700d44d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions std/getopt.d
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,8 @@ private bool handleOption(R)(string option, R receiver, ref string[] args,
static Tuple!(K, V) getter(string input)
{
auto j = indexOf(input, assignChar);
enforce!GetOptException(j != -1, "Could not find '"
~ to!string(assignChar) ~ "' in argument '" ~ input ~ "'.");
auto key = input[0 .. j];
auto value = input[j + 1 .. $];
return tuple(to!K(key), to!V(value));
Expand All @@ -971,6 +973,26 @@ private bool handleOption(R)(string option, R receiver, ref string[] args,
return ret;
}

// 17574
@system unittest
{
import std.algorithm.searching : startsWith;

try
{
string[string] mapping;
immutable as = arraySep;
arraySep = ",";
scope (exit)
arraySep = as;
string[] args = ["testProgram", "-m", "a=b,c=\"d,e,f\""];
args.getopt("m", &mapping);
assert(false, "Exception not thrown");
}
catch (GetOptException goe)
assert(goe.msg.startsWith("Could not find"));
}

// 5316 - arrays with arraySep
@system unittest
{
Expand Down

0 comments on commit 700d44d

Please sign in to comment.