From: marc tobias Date: Tue, 6 Mar 2018 12:33:19 +0000 (+0100) Subject: ParameterParser: getInt with empty string value throws exception X-Git-Tag: v3.2.0~113^2~3 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/123a3c0347226b9b968fe75960fb660d7b6dda15?hp=d9cd8c6fff18b763a8d404ae203f2723ab65aa4b ParameterParser: getInt with empty string value throws exception --- diff --git a/lib/ParameterParser.php b/lib/ParameterParser.php index 2eed1629..7d8d5dc8 100644 --- a/lib/ParameterParser.php +++ b/lib/ParameterParser.php @@ -23,7 +23,7 @@ class ParameterParser public function getInt($sName, $bDefault = false) { - if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) { + if (!isset($this->aParams[$sName])) { return $bDefault; } diff --git a/test/php/Nominatim/ParameterParserTest.php b/test/php/Nominatim/ParameterParserTest.php index 51b18139..ddc06851 100644 --- a/test/php/Nominatim/ParameterParserTest.php +++ b/test/php/Nominatim/ParameterParserTest.php @@ -16,11 +16,6 @@ class ParameterParserTest extends \PHPUnit_Framework_TestCase { - protected function setUp() - { - } - - public function testGetBool() { $oParams = new ParameterParser([ @@ -46,8 +41,7 @@ class ParameterParserTest extends \PHPUnit_Framework_TestCase $oParams = new ParameterParser([ 'int1' => '5', 'int2' => '-1', - 'int3' => '', - 'int4' => 0 + 'int3' => 0 ]); $this->assertSame(false, $oParams->getInt('non-exists')); @@ -55,15 +49,21 @@ class ParameterParserTest extends \PHPUnit_Framework_TestCase $this->assertSame(5, $oParams->getInt('int1')); $this->assertSame(-1, $oParams->getInt('int2')); - $this->assertSame(false, $oParams->getInt('int3')); // FIXME: should be 0 instead? - $this->assertSame(0, $oParams->getInt('int4')); + $this->assertSame(0, $oParams->getInt('int3')); + } + + + public function testGetIntWithNonNumber() + { + $this->setExpectedException(Exception::class, "Integer number expected for parameter 'int4'"); + (new ParameterParser(['int4' => 'a']))->getInt('int4'); } public function testGetIntWithEmpytString() { $this->setExpectedException(Exception::class, "Integer number expected for parameter 'int5'"); - (new ParameterParser(['int5' => 'a']))->getInt('int5'); + (new ParameterParser(['int5' => '']))->getInt('int5'); }