Problem/Motivation

It is not possible to use valid HTML tags such as em and strong in the captions, aka figcaption. They are rendered as is, as plain text, instead of being processed / stripped by the filters.

Proposed resolution

Let the text format process the caption with its FilterCaption filter by removing the ::escapeValues callback from the EntityEmbedDialog's caption field. FilterCaption performs a XSS filtering check, so we could already be safe on this side.

If the EntityEmbedDialog::escapeValues function is not called anymore, maybe deprecate it or make it more obvious it is a convenience static function for use in other classes.

Additional information

Drupal 8.5.4.

Comments

Dakwamine created an issue. See original summary.

dakwamine’s picture

Status: Active » Needs review
StatusFileSize
new524 bytes

Putting a patch as a starting point for work.

By just removing this line, the FilterCaption filter will be able to process properly captions.

Status: Needs review » Needs work

The last submitted patch, 2: cannot_insert_valid_html_in_captions-2990624-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

wim leers’s picture

Title: Cannot insert valid HTML tags in captions » Cannot insert valid HTML tags in captions + test coverage for interaction with core's FilterCaption
Issue tags: +Needs tests
wim leers’s picture

If we can make #2282957: Caption should work like the drupalimage plugin (editable in WYSIWYG, not in dialog) work, this wouldn't be necessary. And the usability would be far better. Still, this is probably worth doing in the short term, until that happens.

wim leers’s picture

wim leers’s picture

Issue tags: +BarcelonaMediaSprint
wim leers’s picture

Status: Needs work » Closed (cannot reproduce)
Issue tags: -Needs tests +Media Initiative
StatusFileSize
new88.24 KB
new132.87 KB
new208.84 KB

Actually … I cannot reproduce this at all; it's already working fine. Perhaps this was caused by one of the other bugs we fixed in the past week.

I entered some HTML in Entity Embed's dialog's "Caption" field:

And it looked correct in CKEditor:

As well as on the front end after saving: