preg_split in _filter_url breaks for long html tags

Created on 27 September 2021, about 3 years ago
Updated 23 March 2023, over 1 year ago

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

1) Provide a patch
2) Review the patch
3) Commit :)

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

Probably not needed

πŸ› Bug report
Status

Fixed

Version

9.5

Component
FilterΒ  β†’

Last updated 3 days ago

No maintainer
Created by

πŸ‡¨πŸ‡·Costa Rica kporras07

Live updates comments and jobs are added and updated live.
  • PHP 8.0

    The issue particularly affects sites running on PHP version 8.0.0 or later.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • Status changed to RTBC almost 2 years ago
  • πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

    Works as expected.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Committed and pushed e7ded38076 to 10.1.x and 687473d5fc to 10.0.x and bcd7a66c05 to 9.5.x. Thanks!

  • Status changed to Fixed almost 2 years ago
    • alexpott β†’ committed e7ded380 on 10.1.x
      Issue #3239472 by stefanos.petrakis, danflanagan8, sjerdo, kporras07,...
    • alexpott β†’ committed 687473d5 on 10.0.x
      Issue #3239472 by stefanos.petrakis, danflanagan8, sjerdo, kporras07,...
    • alexpott β†’ committed bcd7a66c on 9.5.x
      Issue #3239472 by stefanos.petrakis, danflanagan8, sjerdo, kporras07,...
  • πŸ‡¨πŸ‡¦Canada joseph.olstad

    Thanks for the above fix,

    Just hit this with PHP 8.1 / D9.5.5 and search_api, I added fields with phonetic and spellcheck type in the search index, indexed content, it got half way and on some weird content indexing an exception occured as described in this patch declaration
    using this patch until a tagged release comes:

    "3239472 - PHP 8.1 filter when using spellcheck search api field type and phonetic, indexing came up with this TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in _filter_url() (line 539 of core/modules/filter/filter.module": "https://git.drupalcode.org/project/drupal/-/commit/bcd7a66c05d470271f49939cf5e6925892041da3.diff"

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

  • πŸ‡¨πŸ‡¦Canada Nathan Tsai

    Encountered this issue today. Fixed by updating to Drupal 9.5.7.

    [17-Apr-2023 13:06:48 America/Toronto] TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in /home/USER/public_html/core/modules/filter/filter.module on line 539 #0 /home/USER/public_html/core/modules/filter/src/Plugin/Filter/FilterUrl.php(42): _filter_url('<p>\xC2\xA0</p>\n\n<p><...', Object(Drupal\filter\Plugin\Filter\FilterUrl))
    #1 /home/USER/public_html/core/modules/filter/src/Element/ProcessedText.php(118): Drupal\filter\Plugin\Filter\FilterUrl->process('<p>\xC2\xA0</p>\n\n<p><...', 'en')
    #2 [internal function]: Drupal\filter\Element\ProcessedText::preRenderText(Array)
    #3 /home/USER/public_html/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(101): call_user_func_array(Array, Array)
    #4 /home/USER/public_html/core/lib/Drupal/Core/Render/Renderer.php(788): Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_ren...', 'exception', 'Drupal\\Core\\Ren...')
    #5 /home/USER/public_html/core/lib/Drupal/Core/Render/Renderer.php(374): Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array)
    #6 /home/v/USERublic_html/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender(Array, false)
    #7 /home/USER/public_html/core/modules/views/src/Plugin/views/field/EntityField.php(934): Drupal\Core\Render\Renderer->render(Array)
    #8 /home/USER/public_html/core/modules/views/src/Plugin/views/field/FieldPluginBase.php(1171): Drupal\views\Plugin\views\field\EntityField->render_item(0, Array)
    #9 /home/USER/public_html/core/modules/views/views.theme.inc(238): Drupal\views\Plugin\views\field\FieldPluginBase->advancedRender(Object(Drupal\views\ResultRow))
    #10 [internal function]: template_preprocess_views_view_field(Array, 'views_view_fiel...', Array)
    #11 /home/USER/public_html/core/lib/Drupal/Core/Theme/ThemeManager.php(287): call_user_func_array('template_prepro...', Array)
    
Production build 0.71.5 2024