diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php index 8723bbff8f452c5fda97679028482bc5736b0c8c..b25bdfb2300247839364b85a67d0511a685ab6e3 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php @@ -199,7 +199,7 @@ function testOptionsAllowedValuesText() { } /** - * Options (boolen) : test 'On/Off' values input. + * Options (boolean) : test 'On/Off' values input. */ function testOptionsAllowedValuesBoolean() { $this->field_name = 'field_options_boolean'; @@ -225,6 +225,19 @@ function testOptionsAllowedValuesBoolean() { $this->assertFalse(isset($field['settings']['off']), 'The off value is not saved into settings'); } + /** + * Options (text) : test 'trimmed values' input. + */ + function testOptionsTrimmedValuesText() { + $this->field_name = 'field_options_trimmed_text'; + $this->createOptionsField('list_text'); + + // Explicit keys. + $string = "zero |Zero\none | One"; + $array = array('zero' => 'Zero', 'one' => 'One'); + $this->assertAllowedValuesInput($string, $array, 'Explicit keys are accepted and trimmed.'); + } + /** * Helper function to create list field of a given type. * diff --git a/core/modules/options/options.module b/core/modules/options/options.module index b49d16b89393eba1ce0d8b871faedcf848c87b09..c63f3641914e819e151c09df78b789bb6cd87ef3 100644 --- a/core/modules/options/options.module +++ b/core/modules/options/options.module @@ -304,8 +304,9 @@ function options_extract_allowed_values($string, $field_type, $generate_keys) { // Check for an explicit key. $matches = array(); if (preg_match('/(.*)\|(.*)/', $text, $matches)) { - $key = $matches[1]; - $value = $matches[2]; + // Trim key and value to avoid unwanted spaces issues. + $key = trim($matches[1]); + $value = trim($matches[2]); $explicit_keys = TRUE; } // Otherwise see if we can use the value as the key. Detecting true integer