summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcatch2013-01-17 21:25:57 (GMT)
committercatch2013-01-17 21:25:57 (GMT)
commit5ff1cee3839d038c37df943635449655992e3afa (patch)
treee7c4b15a412e417b1b2382b84f2f747e767119f0
parent3af2941e485e43d470041f919e85f7a2dd8aa3ac (diff)
Issue #1029060 by plopesc, Kars-T: Should allowed options for list fields trim() the strings?.
-rw-r--r--core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php15
-rw-r--r--core/modules/options/options.module5
2 files changed, 17 insertions, 3 deletions
diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php
index 8723bbf..b25bdfb 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 @@ class OptionsFieldUITest extends FieldTestBase {
}
/**
- * Options (boolen) : test 'On/Off' values input.
+ * Options (boolean) : test 'On/Off' values input.
*/
function testOptionsAllowedValuesBoolean() {
$this->field_name = 'field_options_boolean';
@@ -226,6 +226,19 @@ class OptionsFieldUITest extends FieldTestBase {
}
/**
+ * 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.
*
* @param string $type
diff --git a/core/modules/options/options.module b/core/modules/options/options.module
index b49d16b..c63f364 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