Skip to content

Commit

Permalink
Merge pull request #46 from WebFiori/fix-bug-45
Browse files Browse the repository at this point in the history
Fix Bug #45
  • Loading branch information
usernane committed Aug 10, 2023
2 parents c153c46 + 5c713ba commit 8461a18
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
26 changes: 26 additions & 0 deletions tests/webfiori/tests/http/APIFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,32 @@ public function testFilterGet23() {
$this->assertEquals(1,count($filtered));
$this->assertEquals([false, "Hello", null, "World"],$filtered['array']);
}
/**
* @test
*/
public function testFilterGet31() {
$this->apiFilter = new APIFilter();
$param00 = new RequestParameter('array', 'array');
$this->apiFilter->addRequestParameter($param00);
$_GET['array'] = [false, "Hello", null, "World"];
$this->apiFilter->filterGET();
$filtered = $this->apiFilter->getInputs();
$this->assertEquals(1,count($filtered));
$this->assertEquals([false, "Hello", null, "World"],$filtered['array']);
}
/**
* @test
*/
public function testFilterGet32() {
$this->apiFilter = new APIFilter();
$param00 = new RequestParameter('array', 'array');
$this->apiFilter->addRequestParameter($param00);
$_GET['array'] = [false, ["Hello"], null, "World"];
$this->apiFilter->filterGET();
$filtered = $this->apiFilter->getInputs();
$this->assertEquals(1,count($filtered));
$this->assertEquals([false, ["Hello"], null, "World"],$filtered['array']);
}
/**
* @test
*/
Expand Down
20 changes: 19 additions & 1 deletion webfiori/http/APIFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ public static function filter(APIFilter $apiFilter, array $arr): array {
$defaultVal = $def[$paramIdx]->getDefault();

if (isset($arr[$name])) {
$toBeFiltered = urldecode($arr[$name]);
if (gettype($arr[$name]) != 'array') {
$toBeFiltered = urldecode($arr[$name]);
} else {
$toBeFiltered = self::decodeArray($arr[$name]);
}
$retVal[$noFIdx][$name] = $toBeFiltered;

if (isset($def[$optIdx]['filter-func'])) {
Expand All @@ -194,6 +198,17 @@ public static function filter(APIFilter $apiFilter, array $arr): array {

return $retVal;
}
private static function decodeArray(array $array) {
$retVal = [];
foreach ($array as $arrEl) {
if (gettype($arrEl) == 'array') {
$retVal[] = self::decodeArray($arrEl);
} else {
$retVal[] = urldecode($arrEl.'');
}
}
return $retVal;
}
/**
* Validate and sanitize GET parameters.
*
Expand Down Expand Up @@ -341,6 +356,9 @@ public function setInputStream($pathOrResource) : bool {
return false;
}
private static function applyBasicFilterOnly($def,$toBeFiltered) {
if (gettype($toBeFiltered) == 'array') {
return $toBeFiltered;
}
$toBeFiltered = strip_tags($toBeFiltered);

$paramObj = $def['parameter'];
Expand Down

0 comments on commit 8461a18

Please sign in to comment.