Skip to content

Commit cb89523

Browse files
authored
Merge pull request #10 from msztorc/empty-value
#9 - empty value hotfix
2 parents d27667a + be5a980 commit cb89523

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/Env.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private function _preg_quote_except(string $str, string $exclude, ?string $delim
152152
*/
153153
private function _prepareValue(string $value): string
154154
{
155-
if (false !== strpos($value, ' ') || in_array($value[0], ['=', '$'])) {
155+
if (false !== strpos($value, ' ') || (strlen($value) && in_array($value[0], ['=', '$']))) {
156156
$value = '"' . $value . '"';
157157
}
158158

tests/EnvArtisanTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,17 @@ public function testUrls(): void
151151
->expectsOutput($app_url)
152152
->assertExitCode(0);
153153
}
154+
155+
public function testEmptyValue(): void
156+
{
157+
$app_name = '';
158+
159+
$this->artisan('env:set', ['key' => 'APP_NAME' .'=' . ''])
160+
->expectsOutput("Environment variable with key 'APP_NAME' has been set to '{$app_name}'")
161+
->assertExitCode(0);
162+
163+
$this->artisan('env:get', ['key' => 'APP_NAME'])
164+
->expectsOutput($app_name)
165+
->assertExitCode(0);
166+
}
154167
}

tests/EnvClassTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,13 @@ public function testUrls(): void
208208
$ver_value = $env->getValue('APP_URL');
209209
$this->assertEquals($app_url, $ver_value);
210210
}
211+
212+
public function testEmptyValue(): void
213+
{
214+
$env = new Env();
215+
$env->setValue('APP_NAME', '');
216+
$ver_value = $env->getValue('APP_NAME');
217+
$this->assertEmpty($ver_value);
218+
$this->assertEquals('', $ver_value);
219+
}
211220
}

0 commit comments

Comments
 (0)