mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
fix #5195: allow empty values in Enum
This commit is contained in:
parent
ce560e7b76
commit
4c741125c5
@ -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;
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user