mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Make formatting tag removal smarter.
Instead of removing all tags, only known formatting tags. Fixes #2203
This commit is contained in:
parent
18a34c03a4
commit
98a8f44fa7
2 changed files with 15 additions and 1 deletions
|
@ -178,7 +178,8 @@ class ConsoleOutput {
|
|||
return $text;
|
||||
}
|
||||
if ($this->_outputAs == self::PLAIN) {
|
||||
return strip_tags($text);
|
||||
$tags = implode('|', array_keys(self::$_styles));
|
||||
return preg_replace('#</?(?:' . $tags . ')>#', '', $text);
|
||||
}
|
||||
return preg_replace_callback(
|
||||
'/<(?<tag>[a-z0-9-_]+)>(?<text>.*?)<\/(\1)>/ims', array($this, '_replaceTags'), $text
|
||||
|
|
|
@ -225,4 +225,17 @@ class ConsoleOutputTest extends CakeTestCase {
|
|||
|
||||
$this->output->write('<error>Bad</error> Regular', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* test plain output only strips tags used for formatting.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testOutputAsPlainSelectiveTagRemoval() {
|
||||
$this->output->outputAs(ConsoleOutput::PLAIN);
|
||||
$this->output->expects($this->once())->method('_write')
|
||||
->with('Bad Regular <b>Left</b> <i>behind</i> <name>');
|
||||
|
||||
$this->output->write('<error>Bad</error> Regular <b>Left</b> <i>behind</i> <name>', false);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue