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
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3360618-1-pregsplit-in-filterurl.patch | 5.46 KB | robertragas |
Issue fork url_embed-3360618
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
robertragas commentedAttached a patch that is similar to the core patch, but with the changes that the url_embed module had.
Comment #3
robertragas commentedComment #5
alyaj2a commentedThanks! This patch #2 function for me.
Comment #8
_shyWas 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
$chunksvariable and wrapped the iteration logic into the if statement to check if$chunksexists.Comment #9
mark_fullmerThanks 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.
Comment #10
_shyThanks for review, @mark_fullmer!
Good point about fallback. I added all required changes to the PR.
Comment #12
mark_fullmerLooks good! Merged and marking as "Fixed"!