"Warning: Undefined array key 1" Warning message received when submitting a webform

Created on 24 April 2024, 2 months ago

Problem/Motivation

We get a lot of the following warning message in our logs:

Warning: Undefined array key 1 in Drupal\spamaway\Plugin\WebformHandler\AntiSpamHandler->validateFormWithSavedSubmissions() (line 374 of modules/contrib/spamaway/src/Plugin/WebformHandler/AntiSpamHandler.php)
#0 core/includes/bootstrap.inc(164): _drupal_error_handler_real()
#1 modules/contrib/spamaway/src/Plugin/WebformHandler/AntiSpamHandler.php(374): _drupal_error_handler()
#2 modules/contrib/spamaway/src/Plugin/WebformHandler/AntiSpamHandler.php(305): Drupal\spamaway\Plugin\WebformHandler\AntiSpamHandler->validateFormWithSavedSubmissions()
#3 modules/contrib/webform/src/Entity/Webform.php(2765): Drupal\spamaway\Plugin\WebformHandler\AntiSpamHandler->validateForm()
#4 modules/contrib/webform/src/WebformSubmissionForm.php(1887): Drupal\webform\Entity\Webform->invokeHandlers()
#5 [internal function]: Drupal\webform\WebformSubmissionForm->validateForm()

Steps to reproduce

  1. Create a webform.
  2. Fill out the webform.
  3. Submit the webform.
🐛 Bug report
Status

RTBC

Version

2.0

Component

Code

Created by

🇨🇦Canada franceslui

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

Comments & Activities

  • Issue created by @franceslui
  • Status changed to Needs review 2 months ago
  • 🇨🇦Canada franceslui

    The code attempts to access array elements based on $index without checking if the $index is within the bounds of the $thresholds array. This leads to "Undefined offset" errors when the $names array has more elements than the $thresholds array.

    We need to ensure that the index access within the $thresholds array is safe by checking that $index is within the array bounds. In my attached patch, I assume that $thresholds[0] should be used if $thresholds[$index] is not set. Please see my attached patch for details.

  • Assigned to abhishek_virasat
  • Issue was unassigned.
  • Status changed to RTBC 2 months ago
  • 🇮🇳India abhishek_virasat

    @kribo, above patch fixes the issue , I have verified locally , also created MR.moving RTBC++

Production build 0.69.0 2024