mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX: In some circumstances, parts of the entities were cut off thus display the LimitCharacters-ed text incorrectly
This commit is contained in:
parent
c6b7b1dc28
commit
8fd309a5ea
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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 & in it' => 'This text contains &...'
|
||||
);
|
||||
|
||||
foreach($cases as $originalValue => $expectedValue) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user