From: Sarah Hoffmann Date: Sat, 23 Jul 2022 08:51:44 +0000 (+0200) Subject: ignore API parameters in array notation X-Git-Tag: v4.1.0~7^2 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/cd4bcea8945d95a43f1e1cb078656c7b452a74ea ignore API parameters in array notation PHP automatically parses parameters in an array notation(foo[]) into array types. Ignore these parameters as 'unknown'. Fixes #2763. --- diff --git a/lib-php/ParameterParser.php b/lib-php/ParameterParser.php index 070be36c..a4936d37 100644 --- a/lib-php/ParameterParser.php +++ b/lib-php/ParameterParser.php @@ -22,7 +22,10 @@ class ParameterParser public function getBool($sName, $bDefault = false) { - if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) { + if (!isset($this->aParams[$sName]) + || !is_string($this->aParams[$sName]) + || strlen($this->aParams[$sName]) == 0 + ) { return $bDefault; } @@ -31,7 +34,7 @@ class ParameterParser public function getInt($sName, $bDefault = false) { - if (!isset($this->aParams[$sName])) { + if (!isset($this->aParams[$sName]) || is_array($this->aParams[$sName])) { return $bDefault; } @@ -44,7 +47,7 @@ class ParameterParser public function getFloat($sName, $bDefault = false) { - if (!isset($this->aParams[$sName])) { + if (!isset($this->aParams[$sName]) || is_array($this->aParams[$sName])) { return $bDefault; } @@ -57,7 +60,10 @@ class ParameterParser public function getString($sName, $bDefault = false) { - if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) { + if (!isset($this->aParams[$sName]) + || !is_string($this->aParams[$sName]) + || strlen($this->aParams[$sName]) == 0 + ) { return $bDefault; } @@ -66,7 +72,10 @@ class ParameterParser public function getSet($sName, $aValues, $sDefault = false) { - if (!isset($this->aParams[$sName]) || strlen($this->aParams[$sName]) == 0) { + if (!isset($this->aParams[$sName]) + || !is_string($this->aParams[$sName]) + || strlen($this->aParams[$sName]) == 0 + ) { return $sDefault; } diff --git a/test/bdd/api/search/params.feature b/test/bdd/api/search/params.feature index 3f12f1c8..300948a9 100644 --- a/test/bdd/api/search/params.feature +++ b/test/bdd/api/search/params.feature @@ -368,3 +368,10 @@ Feature: Search queries | Triesenberg | + Scenario: Array parameters are ignored + When sending json search query "Vaduz" with address + | countrycodes[] | polygon_svg[] | limit[] | polygon_threshold[] | + | IT | 1 | 3 | 3.4 | + Then result addresses contain + | ID | country_code | + | 0 | li | diff --git a/test/php/Nominatim/ParameterParserTest.php b/test/php/Nominatim/ParameterParserTest.php index 7381bdf8..82716d4d 100644 --- a/test/php/Nominatim/ParameterParserTest.php +++ b/test/php/Nominatim/ParameterParserTest.php @@ -137,9 +137,6 @@ class ParameterParserTest extends \PHPUnit\Framework\TestCase public function testGetSet() { - $this->expectException(\Exception::class); - $this->expectExceptionMessage("Parameter 'val3' must be one of: foo, bar"); - $oParams = new ParameterParser(array( 'val1' => 'foo', 'val2' => '', @@ -151,7 +148,7 @@ class ParameterParserTest extends \PHPUnit\Framework\TestCase $this->assertSame('foo', $oParams->getSet('val1', array('foo', 'bar'))); $this->assertSame(false, $oParams->getSet('val2', array('foo', 'bar'))); - $oParams->getSet('val3', array('foo', 'bar')); + $this->assertSame(false, $oParams->getSet('val3', array('foo', 'bar'))); }