Basically this is a copy from the Drupal Core issue https://www.drupal.org/node/3239472

Problem/Motivation

Having a really long HTML tag (e.g. < img > with src:data/image...) makes preg_split fail and return false. On PHP 7.4 this throws a warning ("Warning: count(): Parameter must be an array or an object that implements Countable in _filter_url() (line 535 of core/modules/filter/filter.module).") and makes the field render empty, on PHP 8.0 this throws a fatal error.

Steps to reproduce

1) Have a text format that has Convert URLs into links enabled
2) Using that text format, add a node with content like this: https://gist.github.com/kporras07/618b3bf4cd77ff57fcd5034262220e99
3) Visit the node
4) You will get the warning and empty node or the fatal error depending on your PHP version

Proposed resolution

If $chunks is empty, keep $text.

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork url_embed-3360618

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

robertragas created an issue. See original summary.

robertragas’s picture

StatusFileSize
new5.46 KB

Attached a patch that is similar to the core patch, but with the changes that the url_embed module had.

robertragas’s picture

Status: Active » Needs review

keshav.k made their first commit to this issue’s fork.

alyaj2a’s picture

Version: 2.0.0-alpha1 » 3.x-dev

Thanks! This patch #2 function for me.

_shy made their first commit to this issue’s fork.

_shy’s picture

Was able to reproduce an issue, so I think it would be good to make it work.
I created an MR with the changes suggested above for the current 3.x branch.

In changes, I only added a validation for $chunks variable and wrapped the iteration logic into the if statement to check if $chunks exists.

mark_fullmer’s picture

Status: Needs review » Needs work

Thanks for the work, @_shy! This looks to be a faithful reproduction of the logic from #3239472: preg_split in _filter_url breaks for long html tags, so I think this is on the right track. Just a couple suggestions for implementing the fallback that was added in Drupal core, too.

_shy’s picture

Status: Needs work » Needs review

Thanks for review, @mark_fullmer!

Good point about fallback. I added all required changes to the PR.

  • mark_fullmer committed cbe4c7d3 on 3.x authored by _shy
    refactor: #3360618 preg_split in _filter_url breaks for long html tags
    
mark_fullmer’s picture

Status: Needs review » Fixed

Looks good! Merged and marking as "Fixed"!

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.

Status: Fixed » Closed (fixed)

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