Skip to content

Commit

Permalink
[4.3] Fix issue where line ending in =" is incorrectly marked as a …
Browse files Browse the repository at this point in the history
…multi-line start (#545)
  • Loading branch information
GrahamCampbell authored Oct 16, 2022
1 parent afb6dd2 commit 67a491d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ install:
@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

phpunit:
@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
@docker run -it -w /data -v ${PWD}:/data:delegated --entrypoint vendor/bin/phpunit --rm registry.gitlab.com/grahamcampbell/php:8.2-cli

phpstan-analyze-src:
@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
Expand Down
6 changes: 4 additions & 2 deletions src/Loader/Lines.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ public static function process(array $lines)
*/
private static function multilineProcess($multiline, $line, array $buffer)
{
$startsOnCurrentLine = $multiline ? false : self::looksLikeMultilineStart($line);

// check if $line can be multiline variable
if ($started = self::looksLikeMultilineStart($line)) {
if ($startsOnCurrentLine) {
$multiline = true;
}

if ($multiline) {
array_push($buffer, $line);

if (self::looksLikeMultilineStop($line, $started)) {
if (self::looksLikeMultilineStop($line, $startsOnCurrentLine)) {
$multiline = false;
$line = implode("\n", $buffer);
$buffer = [];
Expand Down
1 change: 1 addition & 0 deletions tests/Dotenv/LinesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function testProcessQuotes()
'TEST_NS=\'test\\ntest\'',
'TEST_EQD="https://vision.googleapis.com/v1/images:annotate?key="',
'TEST_EQS=\'https://vision.googleapis.com/v1/images:annotate?key=\'',
"BASE64_ENCODED_MULTILINE=\"qS1zCzMVVUJWQShokv6YVYi+ruKSC/bHV7GmEiyVkLaBWJHNVHCHsgTksEBsy8wJ\nuwycAvR07ZyOJJed4XTRMKnKp1/v+6UATpWzkIjZXytK+pD+XlZimUHTx3uiDcmU\njhQX1wWSxHDqrSWxeIJiTD+BuUyId8FzmXQ3TcBydJ474tmOU2F492ubk3LAiZ18\nmhiRGoshXAOSbS/P3+RZi4bDeNE/No4=\"",
];

self::assertSame($expected, Lines::process(preg_split("/(\r\n|\n|\r)/", $content)));
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/env/multiline.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ TEST_NS='test\ntest'

TEST_EQD="https://vision.googleapis.com/v1/images:annotate?key="
TEST_EQS='https://vision.googleapis.com/v1/images:annotate?key='

BASE64_ENCODED_MULTILINE="qS1zCzMVVUJWQShokv6YVYi+ruKSC/bHV7GmEiyVkLaBWJHNVHCHsgTksEBsy8wJ
uwycAvR07ZyOJJed4XTRMKnKp1/v+6UATpWzkIjZXytK+pD+XlZimUHTx3uiDcmU
jhQX1wWSxHDqrSWxeIJiTD+BuUyId8FzmXQ3TcBydJ474tmOU2F492ubk3LAiZ18
mhiRGoshXAOSbS/P3+RZi4bDeNE/No4="

0 comments on commit 67a491d

Please sign in to comment.