1
0
Fork 0

Remove ANSI control characters from suggested packages output.

pull/6340/head
Alexander M. Turek 2017-04-08 13:37:25 +02:00
parent be201924cd
commit 401ef69ae3
2 changed files with 29 additions and 2 deletions

View File

@ -116,11 +116,24 @@ class SuggestedPackagesReporter
$this->io->writeError(sprintf( $this->io->writeError(sprintf(
'%s suggests installing %s (%s)', '%s suggests installing %s (%s)',
$suggestion['source'], $suggestion['source'],
$suggestion['target'], $this->removeControlCharacters($suggestion['target']),
$suggestion['reason'] $this->removeControlCharacters($suggestion['reason'])
)); ));
} }
return $this; return $this;
} }
/**
* @param string $string
* @return string
*/
private function removeControlCharacters($string)
{
return preg_replace(
'/[[:cntrl:]]/',
'',
str_replace("\n", ' ', $string)
);
}
} }

View File

@ -144,6 +144,20 @@ class SuggestedPackagesReporterTest extends \PHPUnit_Framework_TestCase
$this->suggestedPackagesReporter->output(); $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 * @covers ::output
*/ */