Skip to content
Snippets Groups Projects
Commit f639b9e9 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #669124 by Arancaytar: list.module incorrectly validated data.

parent 37bacdac
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -156,8 +156,8 @@ function list_allowed_values_setting_validate($element, &$form_state) {
form_error($element, t('Allowed values list: each key must be a valid integer or decimal.'));
break;
}
elseif ($field_type == 'list_text' && strlen($key) > 255) {
form_error($element, t('Allowed values list: each key must be a string less than 255 characters.'));
elseif ($field_type == 'list_text' && drupal_strlen($key) > 255) {
form_error($element, t('Allowed values list: each key must be a string at most 255 characters long.'));
break;
}
elseif ($field_type == 'list' && !preg_match('/^-?\d+$/', $key)) {
......
......@@ -139,33 +139,33 @@ class ListFieldUITestCase extends FieldTestCase {
//Check that non-integer keys are rejected.
$edit = array($element_name => "1.1|one\n");
$this->drupalPost($admin_path, $edit, t('Save settings'));
$this->assertText("keys must be integers", t('Form vaildation failed.'));
$this->assertText("keys must be integers", t('Form validation failed.'));
// Test 'List (number)' field type.
$admin_path = $this->createListFieldAndEdit('list_number');
//Check that non-numeric keys are rejected.
$edit = array($element_name => "1|one\nB|two");
$this->drupalPost($admin_path, $edit, t('Save settings'));
$this->assertText("each key must be a valid integer or decimal", t('Form vaildation failed.'));
$this->assertText("each key must be a valid integer or decimal", t('Form validation failed.'));
//Test 'List (text)' field type.
$admin_path = $this->createListFieldAndEdit('list_text');
//Check that over long keys are rejected.
$edit = array($element_name => "1|one\n" . $this->randomName(255) . "|two");
$edit = array($element_name => "1|one\n" . $this->randomName(256) . "|two");
$this->drupalPost($admin_path, $edit, t('Save settings'));
$this->assertText("each key must be a string less than 255 characters", t('Form vaildation failed.'));
$this->assertText("each key must be a string at most 255 characters long", t('Form validation failed.'));
// Test 'List (boolean)' field type.
$admin_path = $this->createListFieldAndEdit('list_boolean');
// Check that invalid option keys are rejected.
$edit = array($element_name => "1|one\n2|two");
$this->drupalPost($admin_path, $edit, t('Save settings'));
$this->assertText("keys must be either 0 or 1", t('Form vaildation failed.'));
$this->assertText("keys must be either 0 or 1", t('Form validation failed.'));
//Check that missing option causes failure.
$edit = array($element_name => "1|one");
$this->drupalPost($admin_path, $edit, t('Save settings'));
$this->assertText("two values are required", t('Form vaildation failed.'));
$this->assertText("two values are required", t('Form validation failed.'));
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment