FilterCaption hard-codes allowed tags

Created on 18 June 2015, over 9 years ago
Updated 30 January 2023, about 2 years ago

Problem/Motivation

The FilterCaption plugin currently hard-codes which tags are allowed in image captions:

        // Sanitize caption: decode HTML encoding, limit allowed HTML tags; only
        // allow inline tags that are allowed by default, plus <br>.
        $caption = Html::decodeEntities($caption);
        $caption = Xss::filter($caption, array('a', 'em', 'strong', 'cite', 'code', 'br'));

These are also hardcoded into our CKEditor implementation:

        // Override allowedContent setting for the 'caption' nested editable.
        // This must match what caption_filter enforces.
        // @see \Drupal\filter\Plugin\Filter\FilterCaption::process()
        // @see \Drupal\Component\Utility\Xss::filter()
        widgetDefinition.editables.caption.allowedContent = 'a[!href]; em strong cite code br';

There are many other inline HTML tags that one might want to use in image captions, so this should probably be configurable.

Proposed resolution

Make these tags configurable.

Remaining tasks

  • Allow attribute whitelisting.

User interface changes

Would add configuration for the image caption filter.

API changes

Data model changes

Adds configuration options.

Feature request
Status

Needs work

Version

10.1

Component
Filter 

Last updated 5 days ago

No maintainer
Created by

🇺🇸United States jhedstrom Portland, OR

Live updates comments and jobs are added and updated live.
  • wysiwyg

    Involves an in-browser What-You-See-Is-What-You-Get content editor.

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