diff --git a/model/fieldtypes/Enum.php b/model/fieldtypes/Enum.php index cca542aaa..26d9996b1 100644 --- a/model/fieldtypes/Enum.php +++ b/model/fieldtypes/Enum.php @@ -38,7 +38,11 @@ class Enum extends StringField { public function __construct($name = null, $enum = NULL, $default = NULL) { if($enum) { if(!is_array($enum)) { - $enum = preg_split("/\s*,\s*/", trim($enum, ", \t\n\r\0\x0B")); + $enum = preg_split( + "/\s*,\s*/", + // trim commas only if they are on the right with a newline following it + ltrim(preg_replace('/,\s*\n\s*$/','',$enum)) + ); } $this->enum = $enum; diff --git a/tests/forms/EnumFieldTest.php b/tests/forms/EnumFieldTest.php index be1de7754..06531112f 100644 --- a/tests/forms/EnumFieldTest.php +++ b/tests/forms/EnumFieldTest.php @@ -19,6 +19,8 @@ class EnumFieldTest extends SapphireTest { public function testEnumParsing() { $enum = new Enum('testField', " + , + 0, Item1, Item2, Item 3, @@ -29,6 +31,8 @@ class EnumFieldTest extends SapphireTest { "); $this->assertEquals(ArrayLib::valuekey(array( + '', + '0', 'Item1', 'Item2', 'Item 3',