Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita34731e

Browse files
committed
allow environment variables starting with an underscore
1 parent6d288bf commita34731e

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

‎src/Symfony/Component/Dotenv/Dotenv.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
finalclass Dotenv
2727
{
28-
publicconstVARNAME_REGEX ='(?i:[A-Z][A-Z0-9_]*+)';
28+
publicconstVARNAME_REGEX ='(?i:_?[A-Z][A-Z0-9_]*+)';
2929
publicconstSTATE_VARNAME =0;
3030
publicconstSTATE_VALUE =1;
3131

@@ -351,8 +351,8 @@ private function lexValue(): string
351351
++$this->cursor;
352352
$value =str_replace(['\\"','\r','\n'], ['"',"\r","\n"],$value);
353353
$resolvedValue =$value;
354-
$resolvedValue =$this->resolveVariables($resolvedValue,$loadedVars);
355354
$resolvedValue =$this->resolveCommands($resolvedValue,$loadedVars);
355+
$resolvedValue =$this->resolveVariables($resolvedValue,$loadedVars);
356356
$resolvedValue =str_replace('\\\\','\\',$resolvedValue);
357357
$v .=$resolvedValue;
358358
}else {
@@ -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‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public static function getEnvDataWithFormatErrors()
5353
["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"],
5454
["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"],
5555
["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"],
56+
['_=FOO',"Invalid character in variable name in\".env\" at line 1.\n..._=FOO...\n ^ line 1 offset 0"],
5657
];
5758

5859
if ('\\' !== \DIRECTORY_SEPARATOR) {
@@ -175,6 +176,10 @@ public static function getEnvData()
175176
["FOO=\nBAR=\${FOO:=TEST}", ['FOO' =>'TEST','BAR' =>'TEST']],
176177
["FOO=\nBAR=\$FOO:=TEST}", ['FOO' =>'TEST','BAR' =>'TEST}']],
177178
["FOO=foo\nFOOBAR=\${FOO}\${BAR}", ['FOO' =>'foo','FOOBAR' =>'foo']],
179+
180+
// underscores
181+
['_FOO=BAR', ['_FOO' =>'BAR']],
182+
['_FOO_BAR=FOOBAR', ['_FOO_BAR' =>'FOOBAR']],
178183
];
179184

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp