Permalink
Browse files

Fix tag order when closing open tags with TextHelper::truncate()

  • Loading branch information...
1 parent 4e7e06f commit acca796d10255fc7ebbf8a51dcc1f29baf87234b @shama shama committed Dec 25, 2011
Showing with 10 additions and 4 deletions.
  1. +1 −1 lib/Cake/Test/Case/View/Helper/TextHelperTest.php
  2. +9 −3 lib/Cake/View/Helper/TextHelper.php
@@ -129,7 +129,7 @@ public function testTruncate() {
Steve Jobs escrita por Walter Isaacson "<strong>Steve Jobs by Walter
Isaacson</strong>", aquí os dejamos la dirección de amazon donde
podeís adquirirla.</span></p>
-<p><span style="font-size: medium;"><a>... </p></span></a>';
+<p><span style="font-size: medium;"><a>... </a></span></p>';
$this->assertEquals($expected, $result);
}
@@ -287,9 +287,15 @@ class_exists('Multibyte');
$bits = mb_substr($truncate, $spacepos);
preg_match_all('/<\/([a-z]+)>/', $bits, $droppedTags, PREG_SET_ORDER);
if (!empty($droppedTags)) {
- foreach ($droppedTags as $closingTag) {
- if (!in_array($closingTag[1], $openTags)) {
- array_unshift($openTags, $closingTag[1]);
+ if (!empty($openTags)) {
+ foreach ($droppedTags as $closingTag) {
+ if (!in_array($closingTag[1], $openTags)) {
+ array_unshift($openTags, $closingTag[1]);
+ }
+ }
+ } else {
+ foreach ($droppedTags as $closingTag) {
+ array_push($openTags, $closingTag[1]);
}
}
}

0 comments on commit acca796

Please sign in to comment.