add AppwriteDomain validator with inheritance approach

This commit is contained in:
Harsh Mahajan committed 2025-07-29 13:49:51 +05:30
1 parent 80b6347edf
commit b6f9980e02
5 files changed
+18 -38

No files matched your search

@@ -3,7 +3,7 @@
namespace Appwrite\Network\Validator;
use Utopia\System\System;
use Utopia\Validator;
use Utopia\Validator\Domain as ValidatorDomain;
/**
* AppwriteDomain
@@ -14,7 +14,7 @@ use Utopia\Validator;
*
* @package Appwrite\Network\Validator
*/
class AppwriteDomain extends Validator
class AppwriteDomain extends ValidatorDomain
{
protected string $suffix;
@@ -46,8 +46,18 @@ class AppwriteDomain extends Validator
*/
public function isValid($value): bool
{
// Basic validation
if (!is_string($value) || empty($value) || preg_match('/\s/', $value)) {
// Basic validation - check type and spaces first
if (!is_string($value) || empty($value)) {
return false;
}
// Check for spaces (before and after trimming)
if (preg_match('/\s/', $value)) {
return false;
}
// First check if it's a valid domain using parent validator
if (!parent::isValid($value)) {
return false;
}
@@ -88,28 +98,4 @@ class AppwriteDomain extends Validator
return true;
}
/**
* Is array
*
* Function will return false as this validator validates strings.
*
* @return bool
*/
public function isArray(): bool
{
return false;
}
/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return self::TYPE_STRING;
}
}
@@ -19,9 +19,7 @@ use Utopia\Domains\Domain;
use Utopia\Platform\Action;
use Utopia\Platform\Scope\HTTP;
use Utopia\System\System;
use Utopia\Validator\AllOf;
use Utopia\Validator\AnyOf;
use Utopia\Validator\Domain as ValidatorDomain;
use Utopia\Validator\IP;
class Create extends Action
@@ -62,7 +60,7 @@ class Create extends Action
->label('abuse-limit', 10)
->label('abuse-key', 'userId:{userId}, url:{url}')
->label('abuse-time', 60)
->param('domain', null, new AllOf([new ValidatorDomain(), new AppwriteDomain()]), 'Domain name.')
->param('domain', null, new AppwriteDomain(), 'Domain name.')
->inject('response')
->inject('project')
->inject('queueForCertificates')
@@ -21,7 +21,6 @@ use Utopia\Platform\Action;
use Utopia\Platform\Scope\HTTP;
use Utopia\System\System;
use Utopia\Validator\AnyOf;
use Utopia\Validator\Domain as ValidatorDomain;
use Utopia\Validator\IP;
use Utopia\Validator\Text;
@@ -63,7 +62,7 @@ class Create extends Action
->label('abuse-limit', 10)
->label('abuse-key', 'userId:{userId}, url:{url}')
->label('abuse-time', 60)
->param('domain', null, new AllOf([new ValidatorDomain(), new AppwriteDomain()]), 'Domain name.')
->param('domain', null, new AppwriteDomain(), 'Domain name.')
->param('functionId', '', new UID(), 'ID of function to be executed.')
->param('branch', '', new Text(255, 0), 'Name of VCS branch to deploy changes automatically', true)
->inject('response')
@@ -20,9 +20,7 @@ use Utopia\Domains\Domain;
use Utopia\Platform\Action;
use Utopia\Platform\Scope\HTTP;
use Utopia\System\System;
use Utopia\Validator\AllOf;
use Utopia\Validator\AnyOf;
use Utopia\Validator\Domain as ValidatorDomain;
use Utopia\Validator\IP;
use Utopia\Validator\URL;
use Utopia\Validator\WhiteList;
@@ -65,7 +63,7 @@ class Create extends Action
->label('abuse-limit', 10)
->label('abuse-key', 'userId:{userId}, url:{url}')
->label('abuse-time', 60)
->param('domain', null, new AllOf([new ValidatorDomain(), new AppwriteDomain()]), 'Domain name.')
->param('domain', null, new AppwriteDomain(), 'Domain name.')
->param('url', null, new URL(), 'Target URL of redirection')
->param('statusCode', null, new WhiteList([301, 302, 307, 308]), 'Status code of redirection')
->param('resourceId', '', new UID(), 'ID of parent resource.')
@@ -21,7 +21,6 @@ use Utopia\Platform\Action;
use Utopia\Platform\Scope\HTTP;
use Utopia\System\System;
use Utopia\Validator\AnyOf;
use Utopia\Validator\Domain as ValidatorDomain;
use Utopia\Validator\IP;
use Utopia\Validator\Text;
@@ -63,7 +62,7 @@ class Create extends Action
->label('abuse-limit', 10)
->label('abuse-key', 'userId:{userId}, url:{url}')
->label('abuse-time', 60)
->param('domain', null, new AllOf([new ValidatorDomain(), new AppwriteDomain()]), 'Domain name.')
->param('domain', null, new AppwriteDomain(), 'Domain name.')
->param('siteId', '', new UID(), 'ID of site to be executed.')
->param('branch', '', new Text(255, 0), 'Name of VCS branch to deploy changes automatically', true)
->inject('response')