Assertion error if field name could not be used as variable name

Created on 9 September 2024, 2 months ago

Problem/Motivation

I'm using a Drupal module that fetches views data via HTTP. Field names might contain the character :. In that case loading the view fails with the message "Tokens need to be valid Twig variables". This happens even if the field is not used as token.
The origin of this error is here: https://git.drupalcode.org/project/drupal/-/blob/10.3.3/core/modules/vie... (or line 390 or 394)

If evaluating assert() is not enabled, the view loads as expected.

Steps to reproduce

Create a view with a field name that contains a character that doesn't match the regex in the assert() linked above. When the view is loaded either as preview or explicitly the error occurs.

Proposed resolution

Allow field names that aren't allowed as PHP variable names by replacing not allowed characters with another string (e.g. ___) when evaluating tokens. There is a possibility of naming conflicts, though not to be expected. However, code could be added that throws an exception in that case.

πŸ› Bug report
Status

Active

Version

10.3 ✨

Component
ViewsΒ  β†’

Last updated about 5 hours ago

Created by

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

Comments & Activities

Production build 0.71.5 2024