Warning: Array to string conversion in SpamMasterElusiveService->spamMasterElusiveCheck

Created on 7 August 2023, over 1 year ago

Problem/Motivation

When the user send a message through a Contact Form, he gets multiple warnings like this:

Warning: Array to string conversion in Drupal\spammaster\SpamMasterElusiveService->spamMasterElusiveCheck() (line 314 of modules/contrib/spammaster/src/SpamMasterElusiveService.php).

I noticed this after updating Drupal Symfony Mailer to release 1.3.0.

I'm not sure if it's related but I had no problems running in local environment (DDEV PHP 8.1.21) but I did in staging and production (PHP 8.1.11).

Steps to reproduce

Activate and setup the Contact form, Spam Master and Symfony Mailer modules, then send an email using the feedback contact form.

Proposed resolution

Line 314 has a preg_grep function which can't work with multi-dimensional arrays. The $param array is being built in previous lines and doesn't check if the value is a string.

During my debug I noticed values which are arrays like this: $value[0]['value'], so I just added a specific check in the $params constructor loop.

For the existing unsderscore starting keys, I used a continue but this is just to avoid incapsulated if statements that I personally don't like :-)

Remaining tasks

This requires more checks in different setups.

Providing patch file.

🐛 Bug report
Status

Fixed

Version

1.95

Component

Code

Created by

🇮🇹Italy nessunluogo Tremestieri Etneo (CT)

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

Comments & Activities

Production build 0.71.5 2024