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

  1. Enable the "Convert URLs into links" filter on a text format.
  2. Delete the default value for the "Maximum link text length" setting and save the text format.
  3. Create a piece of content using this text format and insert an URL into the body (e.g., https://example.com/foo/bar).
  4. Check the rendered processed text on the frontend.
  5. 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>.
  6. 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

CommentFileSizeAuthor
#2 3619623-2.patch2.75 KBchaitanyadessai

Issue fork drupal-3619623

Command icon 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

pminf created an issue. See original summary.

chaitanyadessai’s picture

Status: Active » Needs review
StatusFileSize
new2.75 KB

Please review patch.

smustgrave’s picture

Version: 11.4.x-dev » main
Status: Needs review » Needs work
Issue tags: +Needs tests

Fixes need to be in MRs and land in main first please.

chaitanyadessai’s picture

Status: Needs work » Needs review

Please review MR

dcam’s picture

Title: Url Filter with no maximum link text length trims to ellipsis only » Empty FilterUrl maximum link text length setting trims to ellipsis only
Issue summary: View changes
Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Thank 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.

alexpott’s picture

Version: main » 11.5.x-dev
Status: Reviewed & tested by the community » Fixed

Backported 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!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • alexpott committed 051a1aca on 11.5.x
    fix: #3619623 Empty FilterUrl maximum link text length setting trims to...

  • alexpott committed 1ff8240c on 11.x
    fix: #3619623 Empty FilterUrl maximum link text length setting trims to...

  • alexpott committed 603a9982 on 12.0.x
    fix: #3619623 Empty FilterUrl maximum link text length setting trims to...

  • alexpott committed 6ed53eb7 on main
    fix: #3619623 Empty FilterUrl maximum link text length setting trims to...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.