Problem/Motivation
When using the "Convert URLs into links" text filter (filter_url) URLs embedded within text are automatically converted into HTML links. If the plugin's "Maximum link text length" setting is unset with a value of NULL or an empty string, then the entire link text is truncated down to only an ellipsis, for example: <a href="https://example.com">...</a>.
This behavior is a regression caused by updating to Drupal 11.4 (related to changes in #3226806: Move filter implementations from filter.module to plugin classes. When maximum link text length limit is configured, no truncation should occur and the full URL should be displayed as the anchor text.
If anyone needs to work around this issue, it is recommended to set maximum length to a high value like 10000.
Steps to reproduce
- Enable the "Convert URLs into links" filter on a text format.
- Delete the default value for the "Maximum link text length" setting and save the text format.
- Create a piece of content using this text format and insert an URL into the body (e.g.,
https://example.com/foo/bar). - Check the rendered processed text on the frontend.
- Expected result: The link is output with the full URL as anchor text:
<a href="https://example.com/foo/bar">https://example.com/foo/bar</a>. - Actual result: The link anchor text is truncated to an ellipsis:
<a href="https://example.com/foo/bar">...</a>
Proposed resolution
Before #3226806 the legacy procedural function, _filter_url_trim(), was responsible for checking whether a length was given before doing any truncation. This condition was not added to its OOP equivalent, FilterUrl::trimUrl(). Add a condition for an early return in trimUrl() if the length setting is NULL or an empty string.
Remaining tasks
User interface changes
Truncated URLs that are being displayed as ellipses in Drupal 11.4+ will be restored to displaying the full URL as link text.
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3619623
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:
- 3619623-url-filter-with
changes, plain diff MR !16939
Comments
Comment #2
chaitanyadessai commentedPlease review patch.
Comment #3
smustgrave commentedFixes need to be in MRs and land in main first please.
Comment #5
chaitanyadessai commentedPlease review MR
Comment #6
dcam commentedThank you for working on this issue.
I was able to reproduce the issue by following the steps in the issue summary. I installed 11.3.0 and with an empty setting the full URL was displayed as the link text. I reinstalled with main and only an ellipsis was displayed as the link text.
This qualifies as a Major bug because it has the potential to interfere with normal use of the site. So I'm increasing the priority.
I updated the issue summary. I felt that it needed some simplification and clarification. I verified that this was actually caused by #3226806: Move filter implementations from filter.module to plugin classes. That is true, so I added the information about what went wrong in that issue to cause this to happen to the IS.
The changes in the MR look good to me. I didn't find anything to comment about. I wondered if it might be more appropriate to put the condition somewhere else in the class in order to preserve the single-responsibility of
trimUrl(), but I don't think so.This looks good to me.
Comment #7
alexpottBackported to 11.5.x as a major but not risky bug fix.
Committed and pushed 6ed53eb76a1 to main and 603a9982f2d to 12.0.x and 1ff8240cf12 to 11.x and 051a1aca43b to 11.5.x. Thanks!