8000 [Dotenv] Duplicate $_SERVER values in $_ENV if they don't exist · Korbeil/symfony@08291b1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 08291b1

Browse files
[Dotenv] Duplicate $_SERVER values in $_ENV if they don't exist
Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
1 parent 195b673 commit 08291b1

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Symfony/Component/Dotenv/Dotenv.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,12 @@ public function populate(array $values, bool $overrideExistingVars = false): voi
136136

137137
foreach ($values as $name => $value) {
138138
$notHttpName = 0 !== strpos($name, 'HTTP_');
139+
if (isset($_SERVER[$name]) && $notHttpName && !isset($_ENV[$name])) {
140+
$_ENV[$name] = $_SERVER[$name];
141+
}
142+
139143
// don't check existence with getenv() because of thread safety issues
140-
if (!isset($loadedVars[$name]) && (!$overrideExistingVars && (isset($_ENV[$name]) || (isset($_SERVER[$name]) && $notHttpName)))) {
144+
if (!isset($loadedVars[$name]) && !$overrideExistingVars && isset($_ENV[$name])) {
141145
continue;
142146
}
143147

src/Symfony/Component/Dotenv/Tests/DotenvTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,4 +493,14 @@ public function testDoNotUsePutenv()
493493
$this->assertSame('no', $_ENV['TEST_USE_PUTENV']);
494494
$this->assertFalse(getenv('TEST_USE_PUTENV'));
495495
}
496+
497+
public function testSERVERVarsDuplicationInENV()
498+
{
499+
unset($_ENV['SYMFONY_DOTENV_VARS'], $_SERVER['SYMFONY_DOTENV_VARS'], $_ENV['FOO']);
500+
$_SERVER['FOO'] = 'CCC';
501+
502+
(new Dotenv(false))->populate(['FOO' => 'BAR']);
503+
504+
$this->assertSame('CCC', $_ENV['FOO']);
505+
}
496506
}

0 commit comments

Comments
 (0)
0