Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make formatting tag removal smarter.

Instead of removing all tags, only known
formatting tags.

Fixes #2203
  • Loading branch information...
commit 98a8f44fa75106e715c454bedb3df5bd5051ce9e 1 parent 18a34c0
@markstory markstory authored
View
3  lib/Cake/Console/ConsoleOutput.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
View
13 lib/Cake/Test/Case/Console/ConsoleOutputTest.php
@@ -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);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.