Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d78bc24

Browse filesBrowse files
stable-staplenicolas-grekas
authored andcommitted
[Process] intersect with getenv() in case-insensitive manner to get default envs
- since environment variables are case-insensitive in Windows, all envs should be compared in case-insensitive manner
1 parent af881a9 commit d78bc24
Copy full SHA for d78bc24

File tree

Expand file treeCollapse file tree

2 files changed

+16
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-4
lines changed

‎src/Symfony/Component/Process/Process.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Process.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@ public function start(callable $callback = null, array $env = [])
304304
$descriptors = $this->getDescriptors();
305305

306306
if ($this->env) {
307-
$env += $this->env;
307+
$env += '\\' === \DIRECTORY_SEPARATOR ? array_diff_ukey($this->env, $env, 'strcasecmp') : $this->env;
308308
}
309309

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

312312
if (\is_array($commandline = $this->commandline)) {
313313
$commandline = implode(' ', array_map([$this, 'escapeArgument'], $commandline));
@@ -1659,8 +1659,8 @@ private function replacePlaceholders(string $commandline, array $env)
16591659
private function getDefaultEnv(): array
16601660
{
16611661
$env = getenv();
1662-
$env = array_intersect_key($env, $_SERVER) ?: $env;
1662+
$env = ('\\' === \DIRECTORY_SEPARATOR ? array_intersect_ukey($env, $_SERVER, 'strcasecmp') : array_intersect_key($env, $_SERVER)) ?: $env;
16631663

1664-
return $_ENV + $env;
1664+
return $_ENV + ('\\' === \DIRECTORY_SEPARATOR ? array_diff_ukey($env, $_ENV, 'strcasecmp') : $env);
16651665
}
16661666
}

‎src/Symfony/Component/Process/Tests/ProcessTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Tests/ProcessTest.php
+12Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.