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 b6c71df

Browse filesBrowse 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 b6c71df
Copy full SHA for b6c71df

File tree

Expand file treeCollapse file tree

2 files changed

+15
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-1
lines changed

‎src/Symfony/Component/Dotenv/Dotenv.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Dotenv/Dotenv.php
+5-1Lines 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

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