Problem/Motivation
When is used in the text field, the “More link” link always appears, even if it is not necessary.
If all characters are removed from the text field, the “More link” link works correctly.
| Comment | File | Size | Author |
|---|---|---|---|
| #26 | smart_trim-3558917-morelink-kernel-test.patch | 2.98 KB | peri22 |
| #17 | 118.diff.txt | 3.17 KB | yusuf_khan |
| #12 | smart-trim-3558917.patch | 1.74 KB | yusuf_khan |
Issue fork smart_trim-3558917
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
steveoriolComment #3
yusuf_khan commentedI’m unable to reproduce the issue on my end; it seems to be working fine. Could you please check the “trim characters” setting? It’s possible that is being counted as a character, which might cause the “More link” to appear unnecessarily.
Comment #4
steveoriolHere's what I have:

Comment #6
yusuf_khan commented@steveoriol,
I have fixed the issue related to ` ` causing the “More link” to appear unnecessarily.
Please review the fix here: [Commit](https://git.drupalcode.org/issue/smart_trim-3558917/-/commit/1d3cf42ae9a...)
Please confirm if the fix works on your end.
Comment #7
yusuf_khan commented@steveoriol, Please find the patch that fixes this issue -
Comment #8
steveoriol@yusuf_khan, Merci !
I confirm that your patch does indeed solve the problem, but it only applies without error with version v2.x-dev, not with version v2.2.0.
Comment #9
_pratik_Hi, I Created a patch for 2.2.0.
Please review. Thanks
Comment #10
yusuf_khan commented@steveoriol patch for version 2.2 , please review and confirm
Comment #11
yusuf_khan commented@steveoriol patch for version 2.2 , please review and confirm
Comment #12
yusuf_khan commented@steveoriol patch for version 2.2 , sorry for the above comment and fault patch . this is working one please review and confirm
Comment #13
markie commentedHello, can we move these patch updates into the MR please
Comment #14
yusuf_khan commented@markie , this is MR , that fix the issue - https://git.drupalcode.org/issue/smart_trim-3558917/-/commit/1d3cf42ae9a...
Comment #15
yusuf_khan commentedComment #16
shubham_pareek_19 commentedI’ve tested the current MR and the issue is not fully resolved yet.
While testing NBSP cases, I also noticed the same behavior with multiple regular spaces.
with a trim length of 10 characters still causes the “Read more” link to appear, even though the visible text length does not exceed the limit.
This shows the problem is not limited to handling.
The trim detection logic is still counting collapsed or normalized whitespace differently from what is actually rendered.
To fully fix this, whitespace normalization (including NBSP and multiple spaces) needs to happen before the trim-length comparison that determines whether content is considered trimmed.
Comment #17
yusuf_khan commentedhttps://git.drupalcode.org/issue/smart_trim-3558917/-/commit/26670d5ce0c... - @shubham_pareek_19 Please test, i have the issue you raised
Comment #19
csakiistvanComment #20
csakiistvanEnvironment
3558917-nbsp-issue)Prerequisites
smart_trimenabled. (non-breaking space), e.g.Hello world, this is a short body.Root cause
The trimmed output was decoded with
html_entity_decode()while the stored original output kept its raw entity. The "trimmed" comparison and the More-link condition therefore always saw the two strings as different when a non-breaking space was present, so the More link was shown even though no trimming occurred.Steps
ddev drush cr and confirm whether the "More" link appears. , and an Article with a long body (over the trim length) that contains .Expected results
 is not treated as trimmed, so no "More" link is shown. behaves the same (no "More" link). .Actual results
Before the fix, a short body containing
 was reported as trimmed and the "More" link appeared even though the content fit within the trim length; the identical text without correctly showed no link. After applying MR !118, the body is correctly treated as not trimmed and shows no "More" link, the plain-text body is unchanged, and a genuinely long body (with ) still shows the "More" link — confirming trimmed content is unaffected.Testing produced with the assistance of an LLM.
Comment #21
csakiistvanComment #22
markie commentedStill needs community review
Comment #24
ultimikeI have updated this fork.
The changes to
src/Plugin/Field/FieldFormatter/SmartTrimFormatter.phplook good to me. Appreciate the effort.But, the Smart Trim module maintainer have a policy of requiring tests for all changes (including bug fixes,) so I am setting this back to "Needs work".
-mike
Comment #25
ultimikeTest added, thanks to Claude Code and attendees of DrupalEasy office hours for working with me on this.
-mike
Comment #26
peri22 commentedThanks for the update and the tests, @ultimike! I reviewed the fork at 0ff8bfc and the formatter change fixes the issue.
The unit tests for the helper method look good. In case you also want coverage of the rendered formatter output, I wrote a kernel test for this specific issue (attached, 'tests/src/Kernel/MoreLinkTest.php'): it fails on 2.x with the reported More link and passes with the fork, and a genuinely trimmed body still gets the link. Feel free to include it if you think it adds value.
Setting to RTBC, as the fix is solid. Thanks!
Comment #27
ultimikeI'm setting this back to needs review because Claude and I have spent the last 90 minutes or so trying to get all tests (including "phpunit (next major)" and "phpunit (next minor)" to run cleanly, without any errors or dependency messages.
Unfortunately, I don't think there's any way to get around deprecation messages since "Using the SYMFONY_DEPRECATIONS_HELPER environment variable to configure test runs is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0" (via one of the test run logs)
The important bit is this: all phpunit tests are passing in all tested versions of Drupal core. The only thing that is stopping us from getting a completely clean test run is deprecation warnings in future versions of Drupal core - we're going to have to live with those.
So, here's what I've done:
1. Added @peri22's kernel test (thanks) and updated it (and our .gitlab-ci.yml) so that it behaves in tests with other versions of Drupal core.
2. Updated the the db text fixture for the upgrade test (it had a bug.)
3. I updated the annotation to a PHP Attribute for the SmartTrimFormatter plugin.
Before merging, I would some eyes on the diff.
thanks,
-mike
Comment #28
markie commentedComment #30
ultimikeMarking as "Fixed" - thanks, @markie!
-mike