Skip to content

Commit

Permalink
Sanitizer: Fixed prefix key bug, and streamlined the API a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesread committed Sep 2, 2023
1 parent 7d1f973 commit 3037f41
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/main/php/libAllure/Sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
class Sanitizer
{
public $filterAllowUndefined = true;
public $onUndefinedDoVariableHunt = false;
private $onUndefinedSearchPrefixKeys = false;

public const INPUT_GET = 1;
public const INPUT_POST = 2;
Expand Down Expand Up @@ -68,6 +68,11 @@ public static function getInstance()
return self::$instance;
}

public function enableSearchingPrefixKeys()
{
$this->onUndefinedSearchPrefixKeys = true;
}

public function triggerFailFilter($message)
{
throw new \Exception($message);
Expand Down Expand Up @@ -109,8 +114,12 @@ private function getInput($name)
return $source[$name];
}

if ($this->onUndefinedDoVariableHunt) {
$val = $this->variableHunt($source, $name);
if ($this->onUndefinedSearchPrefixKeys) {
foreach ($source as $key => $value) {
if (strstr($key, '-' . $name) !== false) {
return $source[$key];
}
}
}

if (!$this->filterAllowUndefined) {
Expand All @@ -120,17 +129,6 @@ private function getInput($name)
return null;
}

private function variableHunt(array $source, $name)
{
foreach ($source as $key => $value) {
if (strstr($key, $name) !== false) {
return $source[$key];
}
}

return false;
}

public function filterId()
{
return $this->filterUint('id');
Expand Down

0 comments on commit 3037f41

Please sign in to comment.