Filter placeholders without arguments are not replaced when HTML corrector filter applied afterwards

Created on 12 June 2024, 5 months ago
Updated 18 September 2024, 2 months ago

Problem/Motivation

When a filter that uses a placeholder, without arguments, is configured in a text format, to run before the filter_htmlcorrector filter, the first filter's placeholder is not replaced on rendering the text. The drupal-filter-placeholder element remains.

A filter might use a placeholder without arguments simply to postpone rendering something that may be expensive to build. I haven't seen any examples in core, but I've come across a custom one before that builds a form in place of a custom token in text.

This is an issue since Drupal 10.2, which started using masterminds/html5 in 🐛 Upgrade filter system to HTML5 Fixed . I would guess it's still the same in later versions, though I haven't actually tested yet.

Steps to reproduce

  1. Configure a text format:
    1. Enable a filter that uses a placeholder without any arguments (I'm not aware of any in core, sorry).
    2. Enable core's 'Correct faulty and chopped off HTML' filter and ensure it runs after that.
  2. Make some content that uses that text format and which would cause that first filter's placeholder to be used.
  3. Expected result: the placeholder is replaced. Actual result: the drupal-filter-placeholder element remains.

Proposed resolution

Do not add the arguments attribute to the placeholder markup when it is empty, so that the placeholder does not get altered by the filter_htmlcorrector filter. (This would then match the behavior of \Drupal\Core\Render\PlaceholderGenerator::createPlaceholder().)

Remaining tasks

Review MR.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

🐛 Bug report
Status

Fixed

Version

10.3

Component
Filter 

Last updated 3 days ago

No maintainer
Created by

🇬🇧United Kingdom james.williams

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024