Data processors do not check type before performing type-specific operations

Created on 5 February 2017, over 7 years ago
Updated 2 September 2024, 6 days ago

The "rules_tokens" and "rules_numeric_offset" RulesDataProcessors do not check the type of $value before performing type-specific operations.

This can lead to errors when $value is an Object, for example when the "Language" condition is used. To see this, add the "Language" condition to any Rule, then trigger that rule. You should see the fatal error "Recoverable fatal error: Object of class Drupal\Core\Language\Language could not be converted to string in Drupal\typed_data\PlaceholderResolver->replacePlaceHolders()".

The proposed patch adds type checking to the two default data processors Rules provides, which aligns made sense as the documentation for \Drupal\rules\Context\DataProcessorInterface::process says that $value is mixed.

πŸ› Bug report
Status

Needs review

Version

4.0

Component

Rules Core

Created by

πŸ‡ΊπŸ‡ΈUnited States samuel.mortenson

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States TR Cascadia
  • πŸ‡ΊπŸ‡ΈUnited States aitala

    I'm utterly confused by the issues threads here...

    I'm getting an error that looks close to this one, but...?

    TypeError: Drupal\typed_data\PlaceholderResolver::scan(): Argument #1 ($text) must be of type string, null given, called in docroot/modules/contrib/rules/src/Plugin/RulesDataProcessor/TokenProcessor.php on line 69 in Drupal\typed_data\PlaceholderResolver->scan() (line 182 of docroot/modules/contrib/typed_data/src/PlaceholderResolver.php).

    Any idea what I need to do here?

    Thanks,
    Eric

  • πŸ‡«πŸ‡·France dcoppel

    Hi,
    I have same error of @aitala by using token annotation in my email actions rules after update to version 4.
    Thanks for help.

  • @aitala @dcoppel I had the same issue as the one you outlined here https://www.drupal.org/project/rules/issues/3469170 πŸ› Using token annotation in rules action crash after update to version 4 Closed: duplicate .

    In the send email portion of the rule I had left the language field empty as it wasn't required but after upgrading to version 4 it started throwing errors. I would suggest checking if you have any empty fields that could be returning null instead of a string.

    For your reference, I have set the language field to @language.current_language_context:language_interface.

  • πŸ‡«πŸ‡·France dcoppel

    @tidunz : thanks for your reply.
    You are right ! It seems that adding the language field to @language.current_language_context:language_interface in email configuration works fine now !
    Thanks a lot for your help !
    Regards

Production build 0.71.5 2024