Skip to content

Commit e59d8e7

Browse files
committed
Show the first actual unsupported character in the error message
1 parent 642374f commit e59d8e7

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/Symfony/Component/Dotenv/.env

-1
This file was deleted.

src/Symfony/Component/Dotenv/Dotenv.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,9 @@ private function resolveVariables($value)
458458
}
459459

460460
if ('' === $value && isset($matches['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));
461+
$unsupportedChars = strpbrk($matches['default_value'], '\'"{$');
462+
if (false !== $unsupportedChars) {
463+
throw $this->createFormatException(sprintf('Unsupported character "%s" found in the default value of variable "$%s".', $unsupportedChars[0], $name));
463464
}
464465

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

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

+2-2
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}", "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"],
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)