Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 642374f

Browse files
committed
Updated the regex and improved the error message
1 parent d2228e8 commit 642374f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Symfony/Component/Dotenv/Dotenv.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ private function resolveVariables($value)
427427
(?!\() # no opening parenthesis
428428
(?P<opening_brace>\{)? # optional brace
429429
(?P<name>'.self::VARNAME_REGEX.')? # var name
430-
(?P<default_value>:-[^\}]+)? # optional default value
430+
(?P<default_value>:-[^\}]++)? # optional default value
431431
(?P<closing_brace>\})? # optional closing brace
432432
/x';
433433

@@ -458,8 +458,8 @@ private function resolveVariables($value)
458458
}
459459

460460
if ('' === $value && isset($matches['default_value'])) {
461-
if (strpbrk($matches['default_value'], '\'"{}$')) {
462-
throw $this->createFormatException('Invalid character in default value');
461+
if (false !== strpbrk($matches['default_value'], '\'"{$')) {
462+
throw $this->createFormatException(sprintf('Unsupported character found in the default value of variable "$%s".', $name));
463463
}
464464

465465
$value = substr($matches['default_value'], 2);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public function getEnvDataWithFormatErrors()
4848
['FOO!', "Missing = in the environment variable declaration in \".env\" at line 1.\n...FOO!...\n ^ line 1 offset 3"],
4949
['FOO=$(echo foo', "Missing closing parenthesis. in \".env\" at line 1.\n...FOO=$(echo foo...\n ^ line 1 offset 14"],
5050
['FOO=$(echo foo'."\n", "Missing closing parenthesis. in \".env\" at line 1.\n...FOO=$(echo foo\\n...\n ^ line 1 offset 14"],
51-
["FOO=\nBAR=\${FOO:-\'a{a}a}", "Invalid character in default value in \".env\" at line 2.\n...\\nBAR=\${FOO:-\'a{a}a}...\n ^ line 2 offset 24"],
52-
["FOO=\nBAR=\${FOO:-a\$a}", "Invalid character in default value in \".env\" at line 2.\n...FOO=\\nBAR=\${FOO:-a\$a}...\n ^ line 2 offset 20"],
51+
["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"],
52+
["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"],
5454
];
5555

0 commit comments

Comments
 (0)