(fix): Fix TypeError in Origin validator when array is passed

Move type check before assignment to prevent TypeError when non-string
value (like array) is passed to Origin::isValid(). The property
\$this->origin is typed as string, so assigning an array before
the is_string() check caused the error.
This commit is contained in:
Chirag Aggarwal
2026-02-11 18:01:18 +05:30
parent 942b90cb2a
commit 1a966741f4
2 changed files with 6 additions and 4 deletions
+4 -4
View File
@@ -51,14 +51,14 @@ class Origin extends Validator
*/
public function isValid($origin): bool
{
$this->origin = $origin;
$this->scheme = null;
$this->host = null;
if (!is_string($origin) || empty($origin)) {
return false;
}
$this->origin = $origin;
$this->scheme = null;
$this->host = null;
$this->scheme = $this->parseScheme($origin);
$this->host = strtolower(parse_url($origin, PHP_URL_HOST) ?? '');
@@ -16,6 +16,8 @@ class OriginTest extends TestCase
$this->assertEquals(false, $validator->isValid(''));
$this->assertEquals(false, $validator->isValid('/'));
$this->assertEquals(false, $validator->isValid([]));
$this->assertEquals(false, $validator->isValid(['http://localhost']));
$this->assertEquals(true, $validator->isValid('https://localhost'));
$this->assertEquals(true, $validator->isValid('http://localhost'));