Skip to content

Commit

Permalink
Merge pull request #35 from utopia-php/fix-whitelist-validator-no-arrays
Browse files Browse the repository at this point in the history
Fix: whitelist validator should reject arrays of values
  • Loading branch information
kodumbeats authored Nov 25, 2021
2 parents 482741e + 0c59ec0 commit cc7629b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Validator/WhiteList.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function getDescription()
*/
public function isArray(): bool
{
return true;
return false;
}

/**
Expand All @@ -116,6 +116,10 @@ public function getType(): string
*/
public function isValid($value)
{
if (\is_array($value)) {
return false;
}

$value = ($this->strict) ? $value : \strtolower($value);

if (!\in_array($value, $this->list, $this->strict)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Validator/WhiteListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testIsValid()
$this->assertEquals($whiteList->isValid(5), false);
$this->assertEquals($whiteList->getList(), ['string1', 'string2', 3, 4]);
$this->assertEquals($whiteList->getType(), \Utopia\Validator::TYPE_STRING); //string by default
$this->assertEquals($whiteList->isArray(), true);
$this->assertEquals($whiteList->isArray(), false);

$whiteList = new WhiteList(['string1', 'string2', 3, 4], false);

Expand Down

0 comments on commit cc7629b

Please sign in to comment.