From 852067c0245add6883123fbc3fc98bb8930c9ebb Mon Sep 17 00:00:00 2001 From: Thibault JUNIN Date: Tue, 24 Oct 2023 15:18:33 +0200 Subject: [PATCH] fix: isList when passing a string Signed-off-by: Thibault JUNIN --- src/Validator.php | 2 +- tests/SimpleTest.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Validator.php b/src/Validator.php index bb73e24..ff498a4 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -445,7 +445,7 @@ public function getErrors(): array public function list(string ...$keys) { foreach ($keys as $key) { - if (!empty($this->getValue($key)) && !array_is_list($this->getValue($key))) { + if (!empty($this->getValue($key)) && (!is_array($this->getValue($key)) || !array_is_list($this->getValue($key)))) { $this->addError($key, ValidationRules::LIST); } } diff --git a/tests/SimpleTest.php b/tests/SimpleTest.php index 6f61eac..80cd6bf 100644 --- a/tests/SimpleTest.php +++ b/tests/SimpleTest.php @@ -228,6 +228,10 @@ public function testList() $validator = $this->createValidator(["abc" => ["abc" => "def", "foo" => "bar"]]); $validator->list("abc"); $this->assertCount(1, $validator->getErrors(), json_encode($validator->getErrors())); + + $validator = $this->createValidator(["abc" => "str"]); + $validator->list("abc"); + $this->assertCount(1, $validator->getErrors(), json_encode($validator->getErrors())); } } \ No newline at end of file