mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
(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:
@@ -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'));
|
||||
|
||||
Reference in New Issue
Block a user