[
https://issues.apache.org/jira/browse/FREEMARKER-219?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17800092#comment-17800092
]
Dániel Dékány commented on FREEMARKER-219:
------------------------------------------
Reading the documentation, it turns out that these are actually the expected
results, and are consistent with how the built-in works in the usual use cases
(which use non-empty terminator string, and often care about word boundaries).
If we cut between words, then we add a space before the terminator string (to
make it clear that you aren't seeing just a word fragment), which is why {{"1
"?truncate_c(1, '')}} only gives back the terminator string (empty in your
case). Also, before the terminator string is added, the string that's already
cut to size is trimmed on the right side, which is why {{" 2"?truncate_c(1,
'')}} won't give back a space.
If you just want to limit length, without all kind of odd rules (that meant to
give a result that looks right when, for example, you give the short preview of
human written text), then you meant to use {{someString[0 ..* maxLength]}}.
Still, I wonder if when the termination string is 0-length, should there be
some additional rules. That complicates the behavior even more, but maybe more
intuitive at the end. But it's also not backward compatible, so, I'm leaning
towards not doing that, and just point at the {{..*}} operator in the
documentation of {{truncate}}.
> truncate_c is not working as expected
> -------------------------------------
>
> Key: FREEMARKER-219
> URL: https://issues.apache.org/jira/browse/FREEMARKER-219
> Project: Apache Freemarker
> Issue Type: Bug
> Components: engine
> Affects Versions: 2.3.31
> Reporter: Mirlan
> Assignee: Dániel Dékány
> Priority: Major
>
> So the String I would like to truncate is {{1234 SOMESTREETSSS AVE NE 123}}
> So the code is as below
> <#assign myField = "1234 SOMESTREETSSS AVE NE 123">
> ${myField?truncate_c(25, '')}
> {{}}
> Expected output is {{1234 SOMESTREETSSS AVE NE}}
> Actual output is {{1234 SOMESTREETSSS AVE N}}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)