BUGFIX: In some circumstances, parts of the entities were cut off thus display the LimitCharacters-ed text incorrectly

This commit is contained in:
phalkun 2010-11-29 16:18:02 +13:00 committed by Ingo Schommer
parent c6b7b1dc28
commit 8fd309a5ea
2 changed files with 13 additions and 2 deletions

View File

@ -25,7 +25,17 @@ class HTMLText extends Text {
*/
function LimitCharacters($limit = 20, $add = "...") {
$value = trim(strip_tags($this->value));
return (strlen($value) > $limit) ? substr($value, 0, $limit) . $add : $value;
// Content html text to plan text before sub string-ing
// to cutting off part of the html entity character
// For example, & because &am
$value = html_entity_decode($value);
$value = (strlen($value) > $limit) ? substr($value, 0, $limit) . $add : $value;
// Convert plan text back to html entities
$value = htmlentities($value);
return $value;
}
/**

View File

@ -11,7 +11,8 @@ class HTMLTextTest extends SapphireTest {
function testLimitCharacters() {
$cases = array(
'The little brown fox jumped over the lazy cow.' => 'The little brown fox...',
'<p>This is some text in a paragraph.</p>' => 'This is some text in...'
'<p>This is some text in a paragraph.</p>' => 'This is some text in...',
'This text contains &amp; in it' => 'This text contains &amp;...'
);
foreach($cases as $originalValue => $expectedValue) {