diff --git a/src/Utility/Text.php b/src/Utility/Text.php index b8754e2b015..94d1a0cd630 100644 --- a/src/Utility/Text.php +++ b/src/Utility/Text.php @@ -506,12 +506,19 @@ public static function highlight($text, $phrase, array $options = []) /** * Strips given text of all links (]+>|im', '', preg_replace('|<\/a>|im', '', $text)); + do { + $text = preg_replace('#]*)?(>|$)#i', '', $text, -1, $count); + } while ($count); + return $text; } /** diff --git a/tests/TestCase/Utility/TextTest.php b/tests/TestCase/Utility/TextTest.php index 7fe968f430b..a8aebf5b79e 100644 --- a/tests/TestCase/Utility/TextTest.php +++ b/tests/TestCase/Utility/TextTest.php @@ -809,6 +809,15 @@ public function testStripLinks() $expected = 'This is a test and some other text'; $result = $this->Text->stripLinks($text); $this->assertEquals($expected, $result); + + $text = ' href=\'bla\'>test>'; + $this->assertEquals('test', $this->Text->stripLinks($text)); + + $text = 'test'; + $this->assertEquals('test', $this->Text->stripLinks($text)); + + $text = 'assertEquals('', $this->Text->stripLinks($text)); } /**