Make formatting tag removal smarter.

Instead of removing all tags, only known
formatting tags.

Fixes #2203
This commit is contained in:
mark_story 2011-11-02 21:50:16 -04:00
parent 18a34c03a4
commit 98a8f44fa7
2 changed files with 15 additions and 1 deletions

View file

@ -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

View file

@ -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);
}
}