Skip to content

Commit

Permalink
Merge pull request #20 from Cannonb4ll/patch-1
Browse files Browse the repository at this point in the history
Values with spaces break application
  • Loading branch information
imliam authored Jul 18, 2020
2 parents b579306 + 5d6820a commit b17a4eb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/EnvironmentSetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ public function handle(): void
public function setEnvVariable(string $envFileContent, string $key, string $value): array
{
$oldPair = $this->readKeyValuePair($envFileContent, $key);

// Wrap values that have a space or equals in quotes to escape them
if (preg_match('/\s/',$value) || strpos($value, '=') !== false) {
$value = '"' . $value . '"';
}

$newPair = $key . '=' . $value;

// For existed key.
Expand Down
12 changes: 10 additions & 2 deletions tests/Unit/EnvironmentSetCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,14 @@ public function setEnvVariableDataProvider(): array
'some_key',
'=========',
str_replace('some_key=some_value',
'some_key==========', $envFileContent),
'some_key="========="', $envFileContent),
],
[
&$envFileContent,
'value_with_spaces',
'this is a value',
str_replace('value_with_spaces=',
'value_with_spaces="this is a value"', $envFileContent),
],
];
}
Expand Down Expand Up @@ -353,6 +360,7 @@ protected function getTestEnvFile(): string
. ' spaces_in_the_quotes = " " ' . "\n"
. 'a_lot_of_equals_signs_one=======' . "\n"
. 'a_lot_of_equals_signs_two = ====== ' . "\n"
. 'a_lot_of_equals_signs_three = "======" ' . "\n";
. 'a_lot_of_equals_signs_three = "======" ' . "\n"
. 'value_with_spaces=' . "\n";
}
}

0 comments on commit b17a4eb

Please sign in to comment.