Permalink
Browse files

Make formatting tag removal smarter.

Instead of removing all tags, only known
formatting tags.

Fixes #2203
  • Loading branch information...
markstory committed Nov 3, 2011
1 parent 18a34c0 commit 98a8f44fa75106e715c454bedb3df5bd5051ce9e
Showing with 15 additions and 1 deletion.
  1. +2 −1 lib/Cake/Console/ConsoleOutput.php
  2. +13 −0 lib/Cake/Test/Case/Console/ConsoleOutputTest.php
@@ -178,7 +178,8 @@ public function styleText($text) {
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 @@ public function testOutputAsPlain() {
$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);
}
}

0 comments on commit 98a8f44

Please sign in to comment.