Skip to content
Closed
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
8 changes: 8 additions & 0 deletions src/Parser/Lines.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public static function process(array $lines)
}
}

// If the input ends while still inside a multiline value, the value
// was never closed. Emit the buffered content as a final entry
// instead of silently discarding it, so the parser reports the same
// missing-closing-quote error the single-quoted case already does.
if ($multiline && $multilineBuffer !== []) {
$output[] = \implode("\n", $multilineBuffer);
}

return $output;
}

Expand Down
16 changes: 16 additions & 0 deletions tests/Dotenv/Parser/LinesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,20 @@ public function testProcessQuotes()

self::assertSame($expected, Lines::process($result->success()->get()));
}

public function testProcessUnterminatedMultilineIsEmittedNotDropped()
{
$result = Regex::split("/(\r\n|\n|\r)/", "FOO=\"bar");
self::assertTrue($result->success()->isDefined());

self::assertSame(['FOO="bar'], Lines::process($result->success()->get()));
}

public function testProcessUnterminatedMultilineDoesNotSwallowFollowingLines()
{
$result = Regex::split("/(\r\n|\n|\r)/", "A=\"oops\nB=keep");
self::assertTrue($result->success()->isDefined());

self::assertSame(["A=\"oops\nB=keep"], Lines::process($result->success()->get()));
}
}