Skip to content

Commit

Permalink
Properly handle the case where an environment variable is an empty st…
Browse files Browse the repository at this point in the history
…ring.

v.idup returns null when called on an empty but non-null array.  This is
undesirable because we want to differentiate between not-present and
empty-but-present.
  • Loading branch information
ttung committed Jul 25, 2016
1 parent f1b26c3 commit f81ddfb
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 f81ddfb

Please sign in to comment.