Unify logic for determining valid placeholder keys and values

Created on 14 September 2023, 12 months ago

Problem/Motivation

This is a followup from πŸ› Prevent the use of placeholders that cannot be converted into strings when creating logs Fixed .

Logic for determining if placeholder keys and values are valid is currently split between \Drupal\Component\Render\FormattableMarkup::placeholderFormat() and \Drupal\Core\Logger\LogMessageParser::parseMessagePlaceholders().

In a nutshell, this logic is that the key should be a string starting with one of [@%:], and the value should be a string, integer, float or \Stringable object (NULL is also accepted, but logs a deprecation notice).

Steps to reproduce

Proposed resolution

To be determined, but new unified API methods for determining if a placeholder key and value are valid might be helpful, rather than splitting this logic between the render and logger subsystems.

Note that some additional logic could make sense as well:

Integers and floats presumably do not actually need to be escaped?

FormattableMarkup::placeholderFormat() could log a warning and ignore non-\Stringable objects, rather than throwing a TypeError when the object is passed to htmlspecialchars() via Drupal\Component\Utility\Html::escape()?

Remaining tasks

Determine what API additions may be useful here, update the proposed resolution and develop a patch.

User interface changes

API changes

To be determined.

Data model changes

Release notes snippet

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component
RenderΒ  β†’

Last updated 2 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States mfb San Francisco

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

Comments & Activities

Production build 0.71.5 2024