]> git.openstreetmap.org Git - nominatim.git/commitdiff
ParameterParser: getFloat with empty string value throws exception
authormarc tobias <mtmail@gmx.net>
Tue, 6 Mar 2018 12:35:27 +0000 (13:35 +0100)
committermarc tobias <mtmail@gmx.net>
Tue, 6 Mar 2018 12:35:27 +0000 (13:35 +0100)
lib/ParameterParser.php
test/php/Nominatim/ParameterParserTest.php

index 7d8d5dc8fef69a9be0d771ceef02647710d29873..feddc3aa1d9b0c7ac79cb8c5e11218b2baf12fff 100644 (file)
@@ -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;
         }
 
index ddc0685134dd2a1364559db90e20508cfbd40f1e..7873953461193d3798465236226867a653de5ffb 100644 (file)
@@ -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');