Skip to content

Commit c3ec5c5

Browse files
committed
bug #23434 [DotEnv] Fix variable substitution (brieucthomas)
This PR was merged into the 3.3 branch. Discussion ---------- [DotEnv] Fix variable substitution | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #23423 | License | MIT | Doc PR | no Commits ------- 1dfcdc7 [DotEnv] Fix variable substitution
2 parents 71c6f99 + 1dfcdc7 commit c3ec5c5

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/Symfony/Component/Dotenv/Dotenv.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ private function resolveVariables($value)
351351
}
352352

353353
$name = $matches[3];
354-
$value = isset($this->values[$name]) ? $this->values[$name] : (isset($_ENV[$name]) ? isset($_ENV[$name]) : (string) getenv($name));
354+
$value = isset($this->values[$name]) ? $this->values[$name] : (isset($_ENV[$name]) ? $_ENV[$name] : (string) getenv($name));
355355

356356
if (!$matches[2] && isset($matches[4])) {
357357
$value .= '}';

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function testParse($data, $expected)
6363
public function getEnvData()
6464
{
6565
putenv('LOCAL=local');
66+
$_ENV['REMOTE'] = 'remote';
6667

6768
$tests = array(
6869
// spaces
@@ -134,6 +135,7 @@ public function getEnvData()
134135
array('FOO=" \\$ "', array('FOO' => ' $ ')),
135136
array('FOO=" $ "', array('FOO' => ' $ ')),
136137
array('BAR=$LOCAL', array('BAR' => 'local')),
138+
array('BAR=$REMOTE', array('BAR' => 'remote')),
137139
array('FOO=$NOTDEFINED', array('FOO' => '')),
138140
);
139141

0 commit comments

Comments
 (0)