Skip to content

Commit 69c00bc

Browse files
authored
Merge pull request #4627 from ttung/empty
Properly handle the case where an environment variable is an empty string
2 parents c6aa7e1 + f81ddfb commit 69c00bc

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

std/process.d

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3204,7 +3204,16 @@ private:
32043204

32053205
// Cache the last call's result.
32063206
static string lastResult;
3207-
if (v != lastResult) lastResult = v.idup;
3207+
if (v.empty)
3208+
{
3209+
// Return non-null array for blank result to distinguish from
3210+
// not-present result.
3211+
lastResult = "";
3212+
}
3213+
else if (v != lastResult)
3214+
{
3215+
lastResult = v.idup;
3216+
}
32083217
value = lastResult;
32093218
return true;
32103219
}
@@ -3233,11 +3242,18 @@ private:
32333242
assertThrown(environment["std_process"]);
32343243

32353244
// get() without default value
3236-
assert (environment.get("std_process") == null);
3245+
assert (environment.get("std_process") is null);
32373246

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

3250+
version (Posix)
3251+
{
3252+
// get() on an empty (but present) value
3253+
environment["std_process"] = "";
3254+
assert(environment.get("std_process") !is null);
3255+
}
3256+
32413257
// Convert to associative array
32423258
auto aa = environment.toAA();
32433259
assert (aa.length > 0);

0 commit comments

Comments
 (0)