Incorrect usage of Token::replace() can corrupt plain text that resembles HTML

Created on 15 February 2022, about 3 years ago
Updated 17 April 2023, almost 2 years ago

Problem/Motivation

The $text parameter of Token::replace() is documented as follows:

The caller is responsible for calling \Drupal\Component\Utility\Html::escape() in case the $text was plain text.

There are instances in core where this does not happen, which means that plain text that resembles HTML would be corrupted. For example an Email action with subject What do you think of the <blink> tag? would get corrupted to What do you think of the tag?.

When fixing this bug, we need to consider that sites might have observed this bug and compensated for it, by setting their subject to What do you think of the &lt;blink&gt; tag?. If we fix this bug, these sites would start sending emails without decoding those escaped entities. However it's hard to see how to fix the bug without this problem, so perhaps we just have to document it clearly in the release notes.

This issue was split off from #2580723: Fix token system confusion, with new function Token::replacePlain() β†’ , see lengthy discussion there for further background.

Proposed resolution

Use the Token::replacePlain() method.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
TokenΒ  β†’

Last updated 5 days ago

No maintainer
Created by

πŸ‡¬πŸ‡§United Kingdom adamps

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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