diff --git a/src/Composer/Installer/SuggestedPackagesReporter.php b/src/Composer/Installer/SuggestedPackagesReporter.php index 935ec50cf..e9d66f6a6 100644 --- a/src/Composer/Installer/SuggestedPackagesReporter.php +++ b/src/Composer/Installer/SuggestedPackagesReporter.php @@ -116,11 +116,24 @@ class SuggestedPackagesReporter $this->io->writeError(sprintf( '%s suggests installing %s (%s)', $suggestion['source'], - $suggestion['target'], - $suggestion['reason'] + $this->removeControlCharacters($suggestion['target']), + $this->removeControlCharacters($suggestion['reason']) )); } return $this; } + + /** + * @param string $string + * @return string + */ + private function removeControlCharacters($string) + { + return preg_replace( + '/[[:cntrl:]]/', + '', + str_replace("\n", ' ', $string) + ); + } } diff --git a/tests/Composer/Test/Installer/SuggestedPackagesReporterTest.php b/tests/Composer/Test/Installer/SuggestedPackagesReporterTest.php index c4cbd72c5..fb88ec840 100644 --- a/tests/Composer/Test/Installer/SuggestedPackagesReporterTest.php +++ b/tests/Composer/Test/Installer/SuggestedPackagesReporterTest.php @@ -144,6 +144,20 @@ class SuggestedPackagesReporterTest extends \PHPUnit_Framework_TestCase $this->suggestedPackagesReporter->output(); } + /** + * @covers ::output + */ + public function testOutputIgnoresFormatting() + { + $this->suggestedPackagesReporter->addPackage('source', 'target', "\x1b[1;37;42m Like us\r\non Facebook \x1b[0m"); + + $this->io->expects($this->once()) + ->method('writeError') + ->with("source suggests installing target ([1;37;42m Like us on Facebook [0m)"); + + $this->suggestedPackagesReporter->output(); + } + /** * @covers ::output */