Skip to content

Commit

Permalink
Fix tag order when closing open tags with TextHelper::truncate()
Browse files Browse the repository at this point in the history
  • Loading branch information
shama committed Dec 25, 2011
1 parent 4e7e06f commit acca796
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/View/Helper/TextHelperTest.php
Expand Up @@ -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);
}

Expand Down
12 changes: 9 additions & 3 deletions lib/Cake/View/Helper/TextHelper.php
Expand Up @@ -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]);
}
}
}
Expand Down

0 comments on commit acca796

Please sign in to comment.