diff --git a/core/lib/Drupal/Core/Form/FormValidator.php b/core/lib/Drupal/Core/Form/FormValidator.php index f8c62379ce0c5dad1ee10be7cb8f1f2d54f0dd81..def5f87191d3cff658337683e7c0cbb2d9950171 100644 --- a/core/lib/Drupal/Core/Form/FormValidator.php +++ b/core/lib/Drupal/Core/Form/FormValidator.php @@ -345,6 +345,12 @@ protected function performRequiredValidation(&$elements, FormStateInterface &$fo if (is_array($elements['#value'])) { $value = in_array($elements['#type'], ['checkboxes', 'tableselect']) ? array_keys($elements['#value']) : $elements['#value']; foreach ($value as $v) { + if (!is_scalar($v)) { + $message_arguments['%type'] = gettype($v); + $form_state->setError($elements, $this->t('The submitted value type %type in the %name element is not allowed.', $message_arguments)); + $this->logger->error('The submitted value type %type in the %name element is not allowed.', $message_arguments); + continue; + } if (!isset($options[$v])) { $message_arguments['%choice'] = $v; $form_state->setError($elements, $this->t('The submitted value %choice in the %name element is not allowed.', $message_arguments)); diff --git a/core/tests/Drupal/Tests/Core/Form/FormValidatorTest.php b/core/tests/Drupal/Tests/Core/Form/FormValidatorTest.php index 18952cecd8ca554ab42a5199e037dfa4ad67fed4..029ed51a46aa5b269840d646591fc6dbfdddf5f1 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormValidatorTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormValidatorTest.php @@ -462,6 +462,19 @@ public static function providerTestPerformRequiredValidation() { 'Test cannot be longer than <em class="placeholder">7</em> characters but is currently <em class="placeholder">8</em> characters long.', FALSE, ], + [ + [ + '#type' => 'select', + '#options' => [ + 'foo' => 'Foo', + 'bar' => 'Bar', + ], + '#value' => [[]], + '#multiple' => TRUE, + ], + 'The submitted value type <em class="placeholder">array</em> in the <em class="placeholder">Test</em> element is not allowed.', + TRUE, + ], ]; }