diff --git a/src/Handlebars/Helpers.php b/src/Handlebars/Helpers.php index 369b0a4..d3bee14 100755 --- a/src/Handlebars/Helpers.php +++ b/src/Handlebars/Helpers.php @@ -561,7 +561,7 @@ public function helperTruncate($template, $context, $args, $source) $limit = $m[2]; $ellipsis = $m[3]; $value = substr($context->get($keyname), 0, $limit); - if ($ellipsis) { + if ($ellipsis && strlen($context->get($keyname)) > $limit) { $value .= $ellipsis; } return $value; diff --git a/tests/Handlebars/HandlebarsTest.php b/tests/Handlebars/HandlebarsTest.php index 3602f4f..495af36 100644 --- a/tests/Handlebars/HandlebarsTest.php +++ b/tests/Handlebars/HandlebarsTest.php @@ -190,6 +190,11 @@ public function internalHelpersdataProvider() "{{#truncate data 8 '...'}}", ["data" => "Hello World! How are you?"], 'Hello Wo...' + ], + [ + "{{#truncate data 8 '...'}}", + ["data" => "Hello"], + 'Hello' ], [ "{{#raw}}I'm raw {{data}}{{/raw}}",