ParameterParser: getStringList removes empty strings

This commit is contained in:
marc tobias
2018-03-06 14:51:48 +01:00
parent 47258f40ea
commit 3ef4c4fbe7
2 changed files with 4 additions and 4 deletions

View File

@@ -74,7 +74,8 @@ class ParameterParser
$sValue = $this->getString($sName); $sValue = $this->getString($sName);
if ($sValue) { if ($sValue) {
return explode(',', $sValue); // removes all NULL, FALSE and Empty Strings but leaves 0 (zero) values
return array_values(array_filter(explode(',', $sValue), 'strlen'));
} }
return $aDefault; return $aDefault;

View File

@@ -115,7 +115,7 @@ class ParameterParserTest extends \PHPUnit_Framework_TestCase
$this->assertSame('default', $oParams->getString('non-exists', 'default')); $this->assertSame('default', $oParams->getString('non-exists', 'default'));
$this->assertSame('abc', $oParams->getString('str1')); $this->assertSame('abc', $oParams->getString('str1'));
$this->assertSame(false, $oParams->getStringList('str2')); $this->assertSame(false, $oParams->getStringList('str2'));
$this->assertSame(false, $oParams->getStringList('str3')); // FIXME: should be 0 instead? $this->assertSame(false, $oParams->getStringList('str3')); // sadly PHP magic treats 0 as false when returned
} }
@@ -155,8 +155,7 @@ class ParameterParserTest extends \PHPUnit_Framework_TestCase
$this->assertSame(false, $oParams->getStringList('non-exists')); $this->assertSame(false, $oParams->getStringList('non-exists'));
$this->assertSame(['a', 'b'], $oParams->getStringList('non-exists', ['a', 'b'])); $this->assertSame(['a', 'b'], $oParams->getStringList('non-exists', ['a', 'b']));
// FIXME: unclear if empty string items should be removed $this->assertSame(['a', 'b', 'c', 'c', 'd'], $oParams->getStringList('list1'));
$this->assertSame(['', 'a', 'b', 'c', '', 'c', 'd'], $oParams->getStringList('list1'));
$this->assertSame(['a'], $oParams->getStringList('list2')); $this->assertSame(['a'], $oParams->getStringList('list2'));
$this->assertSame(false, $oParams->getStringList('list3')); $this->assertSame(false, $oParams->getStringList('list3'));
$this->assertSame(false, $oParams->getStringList('list4')); $this->assertSame(false, $oParams->getStringList('list4'));