8000 bug #58393 [Dotenv] Default value can be empty (HypeMC) · symfony/symfony@db53279 · GitHub
[go: up one dir, main page]

Skip to content

Commit db53279

Browse files
committed
bug #58393 [Dotenv] Default value can be empty (HypeMC)
This PR was merged into the 5.4 branch. Discussion ---------- [Dotenv] Default value can be empty | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT According to the [spec](https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_06_02) the default value for parameter expansion can be an empty string as well, eg: ``` MY_VAR=${OTHER_VAR:-} ``` Commits ------- 17079e8 [Dotenv] Default value can be empty
2 parents 5b5f22b + 17079e8 commit db53279

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Symfony/Component/Dotenv/Dotenv.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ private function resolveVariables(string $value, array $loadedVars): string
495495
(?!\() # no opening parenthesis
496496
(?P<opening_brace>\{)? # optional brace
497497
(?P<name>'.self::VARNAME_REGEX.')? # var name
498-
(?P<default_value>:[-=][^\}]++)? # optional default value
498+
(?P<default_value>:[-=][^\}]*+)? # optional default value
499499
(?P<closing_brace>\})? # optional closing brace
500500
/x';
501501

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@ public static function getEnvData()
175175
["FOO=BAR\nBAR=\${NOTDEFINED:=TEST}", ['FOO' => 'BAR', 'NOTDEFINED' => 'TEST', 'BAR' => 'TEST']],
176176
["FOO=\nBAR=\${FOO:=TEST}", ['FOO' => 'TEST', 'BAR' => 'TEST']],
177177
["FOO=\nBAR=\$FOO:=TEST}", ['FOO' => 'TEST', 'BAR' => 'TEST}']],
178+
["FOO=BAR\nBAR=\${FOO:-}", ['FOO' => 'BAR', 'BAR' => 'BAR']],
179+
["FOO=BAR\nBAR=\${NOTDEFINED:-}", ['FOO' => 'BAR', 'BAR' => '']],
180+
["FOO=\nBAR=\${FOO:-}", ['FOO' => '', 'BAR' => '']],
181+
["FOO=\nBAR=\$FOO:-}", ['FOO' => '', 'BAR' => '}']],
182+
["FOO=BAR\nBAR=\${FOO:=}", ['FOO' => 'BAR', 'BAR' => 'BAR']],
183+
["FOO=BAR\nBAR=\${NOTDEFINED:=}", ['FOO' => 'BAR', 'NOTDEFINED' => '', 'BAR' => '']],
184+
["FOO=\nBAR=\${FOO:=}", ['FOO' => '', 'BAR' => '']],
185+
["FOO=\nBAR=\$FOO:=}", ['FOO' => '', 'BAR' => '}']],
178186
["FOO=foo\nFOOBAR=\${FOO}\${BAR}", ['FOO' => 'foo', 'FOOBAR' => 'foo']],
179187

180188
// underscores

0 commit comments

Comments
 (0)
0