Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Parser/Lines.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ public static function process(array $lines)
}
}

// The input ended while still within a multiline value. Emit what was
// buffered, so that the parser reports the missing closing quote,
// instead of discarding this entry and every line that followed it.
if ($multiline) {
$output[] = \implode("\n", $multilineBuffer);
}

return $output;
}

Expand Down
25 changes: 25 additions & 0 deletions tests/Dotenv/DotenvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Dotenv\Dotenv;
use Dotenv\Exception\InvalidEncodingException;
use Dotenv\Exception\InvalidFileException;
use Dotenv\Exception\InvalidPathException;
use Dotenv\Loader\Loader;
use Dotenv\Parser\Parser;
Expand Down Expand Up @@ -450,6 +451,30 @@ public function testDotenvParseMultilineContainingHash()
);
}

public function testDotenvParseUnterminatedDoubleQuote()
{
$this->expectException(InvalidFileException::class);
$this->expectExceptionMessage('Encountered a missing closing quote at ["bar].');

Dotenv::parse('FOO="bar');
}

public function testDotenvParseUnterminatedDoubleQuoteDoesNotSwallowLaterLines()
{
$this->expectException(InvalidFileException::class);
$this->expectExceptionMessage('Encountered a missing closing quote at ["oops].');

Dotenv::parse("A=\"oops\nB=keep");
}

public function testDotenvParseUnterminatedDoubleQuoteMatchesSingleQuote()
{
$this->expectException(InvalidFileException::class);
$this->expectExceptionMessage('Encountered a missing closing quote at [\'bar].');

Dotenv::parse("FOO='bar");
}

public function testDotenvParseEmptyCase()
{
$output = Dotenv::parse('');
Expand Down