Skip to content

Commit 75c91d6

Browse files
Merge branch '4.4' into 5.3
* 4.4: [Process] intersect with getenv() in case-insensitive manner to get default envs [Serializer] fix support for lazy/unset properties Fix redundant type casts Revert "[DoctrineBridge] add support for the JSON type"
2 parents e498803 + b546181 commit 75c91d6

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Process.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,10 @@ public function start(callable $callback = null, array $env = [])
305305
$descriptors = $this->getDescriptors();
306306

307307
if ($this->env) {
308-
$env += $this->env;
308+
$env += '\\' === \DIRECTORY_SEPARATOR ? array_diff_ukey($this->env, $env, 'strcasecmp') : $this->env;
309309
}
310310

311-
$env += $this->getDefaultEnv();
311+
$env += '\\' === \DIRECTORY_SEPARATOR ? array_diff_ukey($this->getDefaultEnv(), $env, 'strcasecmp') : $this->getDefaultEnv();
312312

313313
if (\is_array($commandline = $this->commandline)) {
314314
$commandline = implode(' ', array_map([$this, 'escapeArgument'], $commandline));
@@ -1647,8 +1647,8 @@ private function replacePlaceholders(string $commandline, array $env)
16471647
private function getDefaultEnv(): array
16481648
{
16491649
$env = getenv();
1650-
$env = array_intersect_key($env, $_SERVER) ?: $env;
1650+
$env = ('\\' === \DIRECTORY_SEPARATOR ? array_intersect_ukey($env, $_SERVER, 'strcasecmp') : array_intersect_key($env, $_SERVER)) ?: $env;
16511651

1652-
return $_ENV + $env;
1652+
return $_ENV + ('\\' === \DIRECTORY_SEPARATOR ? array_diff_ukey($env, $_ENV, 'strcasecmp') : $env);
16531653
}
16541654
}

Tests/ProcessTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,18 @@ public function testWaitStoppedDeadProcess()
15221522
$this->assertFalse($process->isRunning());
15231523
}
15241524

1525+
public function testEnvCaseInsensitiveOnWindows()
1526+
{
1527+
$p = $this->getProcessForCode('print_r([$_SERVER[\'PATH\'] ?? 1, $_SERVER[\'Path\'] ?? 2]);', null, ['PATH' => 'bar/baz']);
1528+
$p->run(null, ['Path' => 'foo/bar']);
1529+
1530+
if ('\\' === \DIRECTORY_SEPARATOR) {
1531+
$this->assertSame('Array ( [0] => 1 [1] => foo/bar )', preg_replace('/\s++/', ' ', trim($p->getOutput())));
1532+
} else {
1533+
$this->assertSame('Array ( [0] => bar/baz [1] => foo/bar )', preg_replace('/\s++/', ' ', trim($p->getOutput())));
1534+
}
1535+
}
1536+
15251537
/**
15261538
* @param string|array $commandline
15271539
* @param mixed $input

0 commit comments

Comments
 (0)