Skip to content

Commit fbe6e96

Browse files
authored
Allow variable with empty value to be updated
1 parent be51ce0 commit fbe6e96

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/EnvironmentSetCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public function handle()
4848
$contents = file_get_contents($envFilePath);
4949

5050
if ($oldValue = $this->getOldValue($contents, $key)) {
51-
$contents = str_replace("{$key}={$oldValue}", "{$key}={$value}", $contents);
51+
$contents = str_replace("{$oldValue}", "{$key}={$value}", $contents);
5252
$this->writeFile($envFilePath, $contents);
5353

54-
return $this->info("Environment variable with key '{$key}' has been changed from '{$oldValue}' to '{$value}'");
54+
return $this->info("Environment variable with key '{$key}' has been updated to '{$value}'");
5555
}
5656

5757
$contents = $contents . "\n{$key}={$value}\n";
@@ -88,7 +88,7 @@ protected function getOldValue(string $envFile, string $key): string
8888
preg_match("/^{$key}=[^\r\n]*/m", $envFile, $matches);
8989

9090
if (count($matches)) {
91-
return substr($matches[0], strlen($key) + 1);
91+
return $matches[0];
9292
}
9393

9494
return '';

0 commit comments

Comments
 (0)