Skip to content

Commit a12524e

Browse files
committed
Variable expansions with a default value should be wrapped in braces
1 parent e59d8e7 commit a12524e

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/Symfony/Component/Dotenv/Dotenv.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,10 @@ private function resolveVariables($value)
458458
}
459459

460460
if ('' === $value && isset($matches['default_value'])) {
461+
if ('{' !== $matches['opening_brace']) {
462+
throw $this->createFormatException(sprintf('Missing braces on variable expansion with default value "%s"', $matches['default_value']));
463+
}
464+
461465
$unsupportedChars = strpbrk($matches['default_value'], '\'"{$');
462466
if (false !== $unsupportedChars) {
463467
throw $this->createFormatException(sprintf('Unsupported character "%s" found in the default value of variable "$%s".', $unsupportedChars[0], $name));

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function getEnvDataWithFormatErrors()
5151
["FOO=\nBAR=\${FOO:-\'a{a}a}", "Unsupported character \"'\" found in the default value of variable \"\$FOO\". in \".env\" at line 2.\n...\\nBAR=\${FOO:-\'a{a}a}...\n ^ line 2 offset 24"],
5252
["FOO=\nBAR=\${FOO:-a\$a}", "Unsupported character \"\$\" found in the default value of variable \"\$FOO\". in \".env\" at line 2.\n...FOO=\\nBAR=\${FOO:-a\$a}...\n ^ line 2 offset 20"],
5353
["FOO=\nBAR=\${FOO:-a\"a}", "Unclosed braces on variable expansion in \".env\" at line 2.\n...FOO=\\nBAR=\${FOO:-a\"a}...\n ^ line 2 offset 17"],
54+
["FOO=\nBAR=\$FOO:-a", "Missing braces on variable expansion with default value \":-a\" in \".env\" at line 2.\n...FOO=\\nBAR=\$FOO:-a...\n ^ line 2 offset 16"],
5455
];
5556

5657
if ('\\' !== \DIRECTORY_SEPARATOR) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy