Skip to content

Commit 119644e

Browse files
committed
allow environment variables starting with an underscore
1 parent 8d06a8a commit 119644e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/Symfony/Component/Dotenv/Dotenv.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
final class Dotenv
2727
{
28-
public const VARNAME_REGEX = '(?i:[A-Z][A-Z0-9_]*+)';
28+
public const VARNAME_REGEX = '(?i:[A-Z_][A-Z0-9_]*+)';
2929
public const STATE_VARNAME = 0;
3030
public const STATE_VALUE = 1;
3131

@@ -374,8 +374,8 @@ private function lexValue(): string
374374
}
375375
$value = rtrim($value);
376376
$resolvedValue = $value;
377-
$resolvedValue = $this->resolveVariables($resolvedValue, $loadedVars);
378377
$resolvedValue = $this->resolveCommands($resolvedValue, $loadedVars);
378+
$resolvedValue = $this->resolveVariables($resolvedValue, $loadedVars);
379379
$resolvedValue = str_replace('\\\\', '\\', $resolvedValue);
380380

381381
if ($resolvedValue === $value && preg_match('/\s+/', $value)) {

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

+4
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ public static function getEnvData()
175175
["FOO=\nBAR=\${FOO:=TEST}", ['FOO' => 'TEST', 'BAR' => 'TEST']],
176176
["FOO=\nBAR=\$FOO:=TEST}", ['FOO' => 'TEST', 'BAR' => 'TEST}']],
177177
["FOO=foo\nFOOBAR=\${FOO}\${BAR}", ['FOO' => 'foo', 'FOOBAR' => 'foo']],
178+
179+
// underscores
180+
['_FOO=BAR', ['_FOO' => 'BAR']],
181+
['_FOO_BAR=FOOBAR', ['_FOO_BAR' => 'FOOBAR']],
178182
];
179183

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

0 commit comments

Comments
 (0)