Custom caption with tokens doesn't render HTML characters

Created on 20 August 2024, 3 months ago
  1. E.g. use token of a plain text field [paragraph:field_item_text] for the Caption
  2. The field itself e.g. has a text like Apples & Oranges
  3. The Caption on Colorbox outputs as Apples & Oranges

Both the Title tag and the Caption.

Also why Title tag is enabled by force assuming by Colorbox itself if it's disabled in the image field? Should respect the image field setting.





🐛 Bug report
Status

Active

Version

2.1

Component

Code

Created by

🇱🇹Lithuania vibrasphere

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

Merge Requests

Comments & Activities

  • Issue created by @vibrasphere
  • 🇱🇹Lithuania vibrasphere

    The DOMPurify library solves the problem for captions on Colorbox itself, but not for HTML Title tag within <img>, it still renders as &amp; which wouldn't be the problem if Title wasn't rendered at all because it is disabled in the image field setting, but somehow Colorbox overrides and forces it.

  • First commit to issue fork.
  • 🇨🇴Colombia ismaelromero Somewhere in the exotic Colombia

    I was able to replicate the error you mentioned in a local environment, as shown in the screenshots below:


    Alternative text configuration


    Sourcecode without entity


    Alt text without entity

    To address this, I added \Drupal\Component\Utility\Html::decodeEntities to Xss::filter($caption) in the _colorbox_formatter_get_caption function located in web/modules/contrib/colorbox/colorbox.theme.inc. I also committed this solution to the 3469260-custom-caption-with-tokens branch.

    After clearing the cache, the updated results can be seen in the following screenshots:


    Source code with entity

    I am submitting the ticket for review and am available for any suggestions or feedback.

  • Pipeline finished with Failed
    22 days ago
    Total: 162s
    #327235
Production build 0.71.5 2024