Skip to content

Commit

Permalink
Support nested variable regex (vlucas#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
C0DE8 authored and GrahamCampbell committed Nov 18, 2017
1 parent 849d8a1 commit fa9d523
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ protected function resolveNestedVariables($value)
if (strpos($value, '$') !== false) {
$loader = $this;
$value = preg_replace_callback(
'/\${([a-zA-Z0-9_]+)}/',
'/\${([a-zA-Z0-9_.]+)}/',
function ($matchedPatterns) use ($loader) {
$nestedVariable = $loader->getEnvironmentVariable($matchedPatterns[1]);
if ($nestedVariable === null) {
Expand Down
2 changes: 2 additions & 0 deletions tests/Dotenv/DotenvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ public function testDotenvNestedEnvironmentVars()
$this->assertSame('{$NVAR1} {$NVAR2}', $_ENV['NVAR3']); // not resolved
$this->assertSame('Hello World!', $_ENV['NVAR4']);
$this->assertSame('$NVAR1 {NVAR2}', $_ENV['NVAR5']); // not resolved
$this->assertSame('Special Value', $_ENV['N.VAR6']); // new '.' (dot) in var name
$this->assertSame('Special Value', $_ENV['NVAR7']); // nested '.' (dot) variable
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/env/nested.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ NVAR2="World!"
NVAR3="{$NVAR1} {$NVAR2}"
NVAR4="${NVAR1} ${NVAR2}"
NVAR5="$NVAR1 {NVAR2}"
N.VAR6="Special Value"
NVAR7="${N.VAR6}"

0 comments on commit fa9d523

Please sign in to comment.