UFM: Fixes the truncate filter to only add ellipsis when text is actually truncated (closes #20395) #20396
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes #20395 - The UFM (Umbraco Flavored Markdown) truncate filter was adding ellipsis even when text was not truncated, leading to confusing UI displays.
Problem
The
truncatefilter in UFM was unconditionally appending the ellipsis/tail to all truncated strings, regardless of whether the original string was actually longer than the specified length. This resulted in short text displaying unnecessary ellipsis marks.Example of incorrect behavior:
As shown in the issue screenshots, this made it appear that content was truncated when it actually wasn't, creating a poor user experience.
Solution
Added a length check before applying the tail/ellipsis:
Now the filter only adds ellipsis when
str.length > length, meaning actual truncation occurred.Corrected behavior:
Changes
Modified:
src/Umbraco.Web.UI.Client/src/packages/ufm/filters/truncate.filter.tsAdded:
src/Umbraco.Web.UI.Client/src/packages/ufm/filters/truncate.filter.test.tsTesting
HtmlStringUtilitiestests pass (4/4)Notes
The C# equivalents (
StringExtensions.TruncateandHtmlStringUtilities.Truncate) already implemented this logic correctly, so this change brings the TypeScript implementation in line with the backend behavior.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
iojs.orgcurl -q --fail --compressed -L -s REDACTED -o -(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.