diff --git a/core/model/fieldtypes/Text.php b/core/model/fieldtypes/Text.php index 823e3bfdb..a74394e56 100644 --- a/core/model/fieldtypes/Text.php +++ b/core/model/fieldtypes/Text.php @@ -27,7 +27,7 @@ class Text extends DBField { * @return string */ function LimitWordCount($numWords = 26, $add = '...') { - $this->value = Convert::xml2raw($this->value); + $this->value = trim(Convert::xml2raw($this->value)); $ret = explode(' ', $this->value, $numWords + 1); if(count($ret) <= $numWords - 1) { diff --git a/tests/fieldtypes/TextTest.php b/tests/fieldtypes/TextTest.php index 73f91c4e0..33cdd617f 100644 --- a/tests/fieldtypes/TextTest.php +++ b/tests/fieldtypes/TextTest.php @@ -12,6 +12,7 @@ class TextTest extends SapphireTest { $cases = array( /* Standard words limited, ellipsis added if truncated */ 'The little brown fox jumped over the lazy cow.' => 'The little brown...', + ' This text has white space around the ends ' => 'This text has...', /* Words less than the limt word count don't get truncated, ellipsis not added */ 'Two words' => 'Two words', // Two words shouldn't have an ellipsis @@ -20,7 +21,8 @@ class TextTest extends SapphireTest { /* HTML tags get stripped out, leaving the raw text */ '
Text inside a paragraph tag should also work
' => 'Text inside a...', - 'Text nested inside another tag should also work
' => 'Text nested inside...' + 'Text nested inside another tag should also work
' => 'Text nested inside...', + 'Two words
' => 'Two words' ); foreach($cases as $originalValue => $expectedValue) {