Invalid expression in Drupal\filter\Plugin\Filter\FilterHtml->filterAttributes()

Created on 15 January 2018, over 6 years ago
Updated 1 March 2023, over 1 year ago

Warning: DOMXPath::query(): Invalid expression in Drupal\filter\Plugin\Filter\FilterHtml->filterAttributes() (line 135 of core/modules/filter/src/Plugin/Filter/FilterHtml.php).

At line 135, this code...

foreach ($xpath->query('//' . $allowed_tag . '[@*]') as $element) {
        $this->filterElementAttributes($element, $allowed_attributes);
      }

...results in a warning in some cases because $allowed_tag is an empty string. Can be fixed by checking for empty around line 115...

foreach ($restrictions['allowed'] as $allowed_tag => $tag_attributes) {
      if (!empty($allowed_tag)) {

Though I'm not sure that's the best fix. Normally arrays are not keyed with empty strings, so it might be necessary to consider why the first item in $restrictions['allowed'] is keyed with an empty string.

This is in a fresh install of Drupal 8. I have created one content item and set the text format in the Body field to Restricted HTML. Setting it to Basic HTML and visiting the content item also triggers the warning. Setting it to Full HTML does not trigger the warning.

πŸ› Bug report
Status

Closed: cannot reproduce

Version

9.5

Component
FilterΒ  β†’

Last updated 2 days ago

No maintainer
Created by

πŸ‡ΊπŸ‡ΈUnited States arnoldbird

Live updates comments and jobs are added and updated live.
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.

Production build 0.71.5 2024