Skip to content

Commit

Permalink
Merge pull request #4627 from ttung/empty
Browse files Browse the repository at this point in the history
Properly handle the case where an environment variable is an empty string
  • Loading branch information
schveiguy authored Jul 30, 2016
2 parents c6aa7e1 + f81ddfb commit 69c00bc
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions std/process.d
Original file line number Diff line number Diff line change
Expand Up @@ -3204,7 +3204,16 @@ private:

// Cache the last call's result.
static string lastResult;
if (v != lastResult) lastResult = v.idup;
if (v.empty)
{
// Return non-null array for blank result to distinguish from
// not-present result.
lastResult = "";
}
else if (v != lastResult)
{
lastResult = v.idup;
}
value = lastResult;
return true;
}
Expand Down Expand Up @@ -3233,11 +3242,18 @@ private:
assertThrown(environment["std_process"]);

// get() without default value
assert (environment.get("std_process") == null);
assert (environment.get("std_process") is null);

// get() with default value
assert (environment.get("std_process", "baz") == "baz");

version (Posix)
{
// get() on an empty (but present) value
environment["std_process"] = "";
assert(environment.get("std_process") !is null);
}

// Convert to associative array
auto aa = environment.toAA();
assert (aa.length > 0);
Expand Down

0 comments on commit 69c00bc

Please sign in to comment.