diff --git a/src/Lines.php b/src/Lines.php index d107e3d6..1fa6c325 100644 --- a/src/Lines.php +++ b/src/Lines.php @@ -42,14 +42,14 @@ public static function process(array $lines) private static function multilineProcess($multiline, $line, array $buffer) { // check if $line can be multiline variable - if (self::looksLikeMultilineStart($line)) { + if ($started = self::looksLikeMultilineStart($line)) { $multiline = true; } if ($multiline) { array_push($buffer, $line); - if (self::looksLikeMultilineStop($line)) { + if (self::looksLikeMultilineStop($line, $started)) { $multiline = false; $line = implode("\n", $buffer); $buffer = []; @@ -72,29 +72,32 @@ private static function looksLikeMultilineStart($line) return false; } - return self::looksLikeMultilineStop($line) === false; + return self::looksLikeMultilineStop($line, true) === false; } /** * Determine if the given line can be the start of a multiline variable. * * @param string $line + * @param bool $started * * @return bool */ - private static function looksLikeMultilineStop($line) + private static function looksLikeMultilineStop($line, $started) { if ($line === '"') { return true; } + $seen = $started ? 0 : 1; + foreach (self::getCharPairs(str_replace('\\\\', '', $line)) as $pair) { - if ($pair[0] !== '\\' && $pair[0] !== '=' && $pair[1] === '"') { - return true; + if ($pair[0] !== '\\' && $pair[1] === '"') { + $seen++; } } - return false; + return $seen > 1; } /** diff --git a/tests/Dotenv/DotenvTest.php b/tests/Dotenv/DotenvTest.php index fe39ac6f..529a3b49 100644 --- a/tests/Dotenv/DotenvTest.php +++ b/tests/Dotenv/DotenvTest.php @@ -288,6 +288,8 @@ public function testMutlilineLoading() $dotenv = Dotenv::create($this->fixturesFolder, 'multiline.env'); $dotenv->load(); $this->assertSame("test\n test\"test\"\n test", getenv('TEST')); + $this->assertSame('https://vision.googleapis.com/v1/images:annotate?key=', getenv('TEST_EQD')); + $this->assertSame('https://vision.googleapis.com/v1/images:annotate?key=', getenv('TEST_EQS')); } public function testDotenvAssertions() diff --git a/tests/Dotenv/LinesTest.php b/tests/Dotenv/LinesTest.php index e69bcc4f..12a8e1fa 100644 --- a/tests/Dotenv/LinesTest.php +++ b/tests/Dotenv/LinesTest.php @@ -30,6 +30,8 @@ public function testProcessQuotes() $expected = [ "TEST=\"test\n test\\\"test\\\"\n test\"", + 'TEST_EQD="https://vision.googleapis.com/v1/images:annotate?key="', + 'TEST_EQS=\'https://vision.googleapis.com/v1/images:annotate?key=\'', ]; $this->assertSame($expected, Lines::process(preg_split("/(\r\n|\n|\r)/", $content))); diff --git a/tests/fixtures/env/multiline.env b/tests/fixtures/env/multiline.env index 5ac3038b..4d95ac81 100644 --- a/tests/fixtures/env/multiline.env +++ b/tests/fixtures/env/multiline.env @@ -1,3 +1,6 @@ TEST="test test\"test\" test" + +TEST_EQD="https://vision.googleapis.com/v1/images:annotate?key=" +TEST_EQS='https://vision.googleapis.com/v1/images:annotate?key='