don't fail when referenced env var does not exist

This commit is contained in:
Christian Flothmann 2019-11-23 15:53:46 +01:00
parent a8a9e69488
commit 8026609dc9
2 changed files with 2 additions and 1 deletions

View File

@ -466,7 +466,7 @@ final class Dotenv
$value = '';
}
if ('' === $value && isset($matches['default_value'])) {
if ('' === $value && isset($matches['default_value']) && '' !== $matches['default_value']) {
$unsupportedChars = strpbrk($matches['default_value'], '\'"{$');
if (false !== $unsupportedChars) {
throw $this->createFormatException(sprintf('Unsupported character "%s" found in the default value of variable "$%s".', $unsupportedChars[0], $name));

View File

@ -172,6 +172,7 @@ class DotenvTest extends TestCase
["FOO=BAR\nBAR=\${NOTDEFINED:=TEST}", ['FOO' => 'BAR', 'NOTDEFINED' => 'TEST', 'BAR' => 'TEST']],
["FOO=\nBAR=\${FOO:=TEST}", ['FOO' => 'TEST', 'BAR' => 'TEST']],
["FOO=\nBAR=\$FOO:=TEST}", ['FOO' => 'TEST', 'BAR' => 'TEST}']],
["FOO=foo\nFOOBAR=\${FOO}\${BAR}", ['FOO' => 'foo', 'FOOBAR' => 'foo']],
];
if ('\\' !== \DIRECTORY_SEPARATOR) {