]> git.openstreetmap.org Git - nominatim.git/commitdiff
ignore API parameters in array notation
authorSarah Hoffmann <lonvia@denofr.de>
Sat, 23 Jul 2022 08:51:44 +0000 (10:51 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Sat, 23 Jul 2022 08:51:44 +0000 (10:51 +0200)
PHP automatically parses parameters in an array notation(foo[]) into
array types. Ignore these parameters as 'unknown'.

Fixes #2763.

lib-php/ParameterParser.php
test/bdd/api/search/params.feature
test/php/Nominatim/ParameterParserTest.php

index 070be36c24a3856448ef3de965298690001dac33..a4936d376d3cb773e31b9acf5386096fc209fc1a 100644 (file)
@@ -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;
         }
 
index 3f12f1c8f563e1c0ec751c14ac5a0ccf35b1722b..300948a9a0765f2c40adea52c5d9dbd6a3587e90 100644 (file)
@@ -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           |
index 7381bdf84a9cca05f13a0aff3ce6f0804076d62b..82716d4de98d68ed29826621759c9d379d1701c4 100644 (file)
@@ -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')));
     }