Fix next line read with double quote blocks in one line

If there was this
FOO="bar"

Then the # comment block was attached to bar because FOO was seen as a
multiline block although the quotes are in one line only
This commit is contained in:
2021-10-11 09:30:36 +09:00
parent c5c40a1780
commit 75367b2724
2 changed files with 3 additions and 1 deletions

View File

@@ -49,11 +49,12 @@ function readEnvFile(string $path = __DIR__, string $env_file = '.env'): int
// wirte only if env is not set yet, and write only the first time
if (empty($_ENV[$var])) {
if (!empty($quotes)) {
$block = true;
// match greedy for first to last so we move any " if there are
if (preg_match('/^"(.*[^\\\])"/U', $value, $matches)) {
$value = $matches[1];
} else {
// this is a multi line
$block = true;
// first " in string remove
// add removed new line back because this is a multi line
$value = ltrim($value, '"') . PHP_EOL;