From a9f1250c1e40664e59d9f7ee76aa4e7e9783e52a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Mon, 5 Dec 2022 16:50:37 +0100 Subject: [PATCH] [Console] Do no preprend empty line if the buffer is empty --- src/Symfony/Component/Console/Style/SymfonyStyle.php | 2 +- .../Style/SymfonyStyle/command/command_23.php | 11 +++++++++++ .../Fixtures/Style/SymfonyStyle/output/output_23.txt | 1 + .../Fixtures/Style/SymfonyStyle/output/output_6.txt | 1 - 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_23.php create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/output/output_23.txt diff --git a/src/Symfony/Component/Console/Style/SymfonyStyle.php b/src/Symfony/Component/Console/Style/SymfonyStyle.php index 997f86279d918..4dde785e86420 100644 --- a/src/Symfony/Component/Console/Style/SymfonyStyle.php +++ b/src/Symfony/Component/Console/Style/SymfonyStyle.php @@ -375,7 +375,7 @@ private function autoPrependText(): void { $fetched = $this->bufferedOutput->fetch(); // Prepend new line if last char isn't EOL: - if (!str_ends_with($fetched, "\n")) { + if ($fetched && !str_ends_with($fetched, "\n")) { $this->newLine(); } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_23.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_23.php new file mode 100644 index 0000000000000..ab32dcaf3e7bf --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_23.php @@ -0,0 +1,11 @@ +text('Hello'); +}; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/output/output_23.txt b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/output/output_23.txt new file mode 100644 index 0000000000000..63105f17b862b --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/output/output_23.txt @@ -0,0 +1 @@ + Hello diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/output/output_6.txt b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/output/output_6.txt index 5f2d33c148a9e..7f1d478a325f7 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/output/output_6.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/output/output_6.txt @@ -1,4 +1,3 @@ - * Lorem ipsum dolor sit amet * consectetur adipiscing elit