Skip to content

Commit 67a491d

Browse files
[4.3] Fix issue where line ending in =" is incorrectly marked as a multi-line start (#545)
1 parent afb6dd2 commit 67a491d

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ install:
33
@docker run -it -w /data -v ${PWD}:/data:delegated -v ~/.composer:/root/.composer:delegated --entrypoint composer --rm registry.gitlab.com/grahamcampbell/php:8.2-base bin all update
44

55
phpunit:
6-
@rm -f bootstrap/cache/*.php && docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/phpunit --rm registry.gitlab.com/grahamcampbell/php:8.2-cli
6+
@docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/phpunit --rm registry.gitlab.com/grahamcampbell/php:8.2-cli
77

88
phpstan-analyze-src:
99
@docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/phpstan --rm registry.gitlab.com/grahamcampbell/php:8.2-cli analyze src -c phpstan.src.neon.dist

src/Loader/Lines.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,17 @@ public static function process(array $lines)
4141
*/
4242
private static function multilineProcess($multiline, $line, array $buffer)
4343
{
44+
$startsOnCurrentLine = $multiline ? false : self::looksLikeMultilineStart($line);
45+
4446
// check if $line can be multiline variable
45-
if ($started = self::looksLikeMultilineStart($line)) {
47+
if ($startsOnCurrentLine) {
4648
$multiline = true;
4749
}
4850

4951
if ($multiline) {
5052
array_push($buffer, $line);
5153

52-
if (self::looksLikeMultilineStop($line, $started)) {
54+
if (self::looksLikeMultilineStop($line, $startsOnCurrentLine)) {
5355
$multiline = false;
5456
$line = implode("\n", $buffer);
5557
$buffer = [];

tests/Dotenv/LinesTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function testProcessQuotes()
3636
'TEST_NS=\'test\\ntest\'',
3737
'TEST_EQD="https://vision.googleapis.com/v1/images:annotate?key="',
3838
'TEST_EQS=\'https://vision.googleapis.com/v1/images:annotate?key=\'',
39+
"BASE64_ENCODED_MULTILINE=\"qS1zCzMVVUJWQShokv6YVYi+ruKSC/bHV7GmEiyVkLaBWJHNVHCHsgTksEBsy8wJ\nuwycAvR07ZyOJJed4XTRMKnKp1/v+6UATpWzkIjZXytK+pD+XlZimUHTx3uiDcmU\njhQX1wWSxHDqrSWxeIJiTD+BuUyId8FzmXQ3TcBydJ474tmOU2F492ubk3LAiZ18\nmhiRGoshXAOSbS/P3+RZi4bDeNE/No4=\"",
3940
];
4041

4142
self::assertSame($expected, Lines::process(preg_split("/(\r\n|\n|\r)/", $content)));

tests/fixtures/env/multiline.env

+5
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ TEST_NS='test\ntest'
77

88
TEST_EQD="https://vision.googleapis.com/v1/images:annotate?key="
99
TEST_EQS='https://vision.googleapis.com/v1/images:annotate?key='
10+
11+
BASE64_ENCODED_MULTILINE="qS1zCzMVVUJWQShokv6YVYi+ruKSC/bHV7GmEiyVkLaBWJHNVHCHsgTksEBsy8wJ
12+
uwycAvR07ZyOJJed4XTRMKnKp1/v+6UATpWzkIjZXytK+pD+XlZimUHTx3uiDcmU
13+
jhQX1wWSxHDqrSWxeIJiTD+BuUyId8FzmXQ3TcBydJ474tmOU2F492ubk3LAiZ18
14+
mhiRGoshXAOSbS/P3+RZi4bDeNE/No4="

0 commit comments

Comments
 (0)