bug #34552 [Dotenv] don't fail when referenced env var does not exist (xabbuh)

This PR was merged into the 4.4 branch.

Discussion
----------

[Dotenv] don't fail when referenced env var does not exist

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34537
| License       | MIT
| Doc PR        |

Commits
-------

8026609dc9 don't fail when referenced env var does not exist
This commit is contained in:
Fabien Potencier 2019-11-24 19:05:55 +01:00
commit 0ea13868fa
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) {