diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 0806fff9e..fbf3ebdc3 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -507,7 +507,7 @@ class Page } $summary = Utils::truncateHTML($content, $size); - + return html_entity_decode($summary); } diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php index c63aa8ffe..c7b9bb4e2 100644 --- a/system/src/Grav/Common/Utils.php +++ b/system/src/Grav/Common/Utils.php @@ -188,7 +188,11 @@ abstract class Utils */ public static function truncateHtml($text, $length = 100, $ellipsis = '...') { - return Truncator::truncateLetters($text, $length, $ellipsis); + if (mb_strlen($text) <= $length) { + return $text; + } else { + return Truncator::truncateLetters($text, $length, $ellipsis); + } } /** diff --git a/tests/unit/Grav/Common/UtilsTest.php b/tests/unit/Grav/Common/UtilsTest.php index d45eee356..61149f239 100644 --- a/tests/unit/Grav/Common/UtilsTest.php +++ b/tests/unit/Grav/Common/UtilsTest.php @@ -129,6 +129,7 @@ class UtilsTest extends \Codeception\TestCase\Test $this->assertEquals('
This is a string to truncate
', Utils::truncateHtml('This is a string to truncate
', 100)); $this->assertEquals('', Utils::truncateHtml('', 6)); $this->assertEquals('This is a string.
\nIt splits two lines.
", Utils::truncateHtml("This is a string.
\nIt splits two lines.
", 100)); } public function testSafeTruncateHtml()