From: marc tobias Date: Tue, 6 Mar 2018 12:35:27 +0000 (+0100) Subject: ParameterParser: getFloat with empty string value throws exception X-Git-Tag: v3.2.0~113^2~2 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/47258f40ea77b9d73c7bfcca1a3489d9adeb30f3 ParameterParser: getFloat with empty string value throws exception --- diff --git a/lib/ParameterParser.php b/lib/ParameterParser.php index 7d8d5dc8..feddc3aa 100644 --- a/lib/ParameterParser.php +++ b/lib/ParameterParser.php @@ -36,7 +36,7 @@ class ParameterParser public function getFloat($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 ddc06851..78739534 100644 --- a/test/php/Nominatim/ParameterParserTest.php +++ b/test/php/Nominatim/ParameterParserTest.php @@ -73,20 +73,23 @@ class ParameterParserTest extends \PHPUnit_Framework_TestCase $oParams = new ParameterParser([ 'float1' => '1.0', 'float2' => '-5', - 'float3' => '', - 'float4' => 0 + 'float3' => 0 ]); $this->assertSame(false, $oParams->getFloat('non-exists')); $this->assertSame(999, $oParams->getFloat('non-exists', 999)); $this->assertSame(1.0, $oParams->getFloat('float1')); $this->assertSame(-5.0, $oParams->getFloat('float2')); - $this->assertSame(false, $oParams->getFloat('float3')); // FIXME: should be 0 instead? - $this->assertSame(0.0, $oParams->getFloat('float4')); + $this->assertSame(0.0, $oParams->getFloat('float3')); } + public function testGetFloatWithEmptyString() + { + $this->setExpectedException(Exception::class, "Floating-point number expected for parameter 'float4'"); + (new ParameterParser(['float4' => '']))->getFloat('float4'); + } - public function testGetFloatWithString() + public function testGetFloatWithTextString() { $this->setExpectedException(Exception::class, "Floating-point number expected for parameter 'float5'"); (new ParameterParser(['float5' => 'a']))->getFloat('float5');