fix #5195: allow empty values in Enum

This commit is contained in:
Joris Debonnet 2016-03-17 22:43:26 +01:00
parent ce560e7b76
commit 4c741125c5
2 changed files with 9 additions and 1 deletions

View File

@ -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;

View File

@ -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',