From 4cb5f06e55b7c58122f8ccb09c67d4e2f5eab32b Mon Sep 17 00:00:00 2001 From: HypeMC Date: Thu, 26 Sep 2024 09:06:08 +0200 Subject: [PATCH] [Dotenv] Default value can be empty --- Dotenv.php | 2 +- Tests/DotenvTest.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Dotenv.php b/Dotenv.php index d164aa0..0fa5bb6 100644 --- a/Dotenv.php +++ b/Dotenv.php @@ -495,7 +495,7 @@ private function resolveVariables(string $value, array $loadedVars): string (?!\() # no opening parenthesis (?P\{)? # optional brace (?P'.self::VARNAME_REGEX.')? # var name - (?P:[-=][^\}]++)? # optional default value + (?P:[-=][^\}]*+)? # optional default value (?P\})? # optional closing brace /x'; diff --git a/Tests/DotenvTest.php b/Tests/DotenvTest.php index 8ba0230..7f8bd27 100644 --- a/Tests/DotenvTest.php +++ b/Tests/DotenvTest.php @@ -175,6 +175,14 @@ public static function getEnvData() ["FOO=BAR\nBAR=\${NOTDEFINED:=TEST}", ['FOO' => 'BAR', 'NOTDEFINED' => 'TEST', 'BAR' => 'TEST']], ["FOO=\nBAR=\${FOO:=TEST}", ['FOO' => 'TEST', 'BAR' => 'TEST']], ["FOO=\nBAR=\$FOO:=TEST}", ['FOO' => 'TEST', 'BAR' => 'TEST}']], + ["FOO=BAR\nBAR=\${FOO:-}", ['FOO' => 'BAR', 'BAR' => 'BAR']], + ["FOO=BAR\nBAR=\${NOTDEFINED:-}", ['FOO' => 'BAR', 'BAR' => '']], + ["FOO=\nBAR=\${FOO:-}", ['FOO' => '', 'BAR' => '']], + ["FOO=\nBAR=\$FOO:-}", ['FOO' => '', 'BAR' => '}']], + ["FOO=BAR\nBAR=\${FOO:=}", ['FOO' => 'BAR', 'BAR' => 'BAR']], + ["FOO=BAR\nBAR=\${NOTDEFINED:=}", ['FOO' => 'BAR', 'NOTDEFINED' => '', 'BAR' => '']], + ["FOO=\nBAR=\${FOO:=}", ['FOO' => '', 'BAR' => '']], + ["FOO=\nBAR=\$FOO:=}", ['FOO' => '', 'BAR' => '}']], ["FOO=foo\nFOOBAR=\${FOO}\${BAR}", ['FOO' => 'foo', 'FOOBAR' => 'foo']], // underscores