mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Fixed email validator
This commit is contained in:
@@ -1200,18 +1200,6 @@ parameters:
|
||||
count: 1
|
||||
path: src/Appwrite/Utopia/Database/Documents/User.php
|
||||
|
||||
-
|
||||
message: '#^Call to method isValid\(\) on an unknown class Utopia\\Validator\\Email\.$#'
|
||||
identifier: class.notFound
|
||||
count: 1
|
||||
path: src/Appwrite/Utopia/Database/Validator/Attributes.php
|
||||
|
||||
-
|
||||
message: '#^Instantiated class Utopia\\Validator\\Email not found\.$#'
|
||||
identifier: class.notFound
|
||||
count: 1
|
||||
path: src/Appwrite/Utopia/Database/Validator/Attributes.php
|
||||
|
||||
-
|
||||
message: '#^Unsafe call to private method Appwrite\\Utopia\\Request\\Filters\\V17\:\:appendSymbol\(\) through static\:\:\.$#'
|
||||
identifier: staticClassAccess.privateMethod
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Network\Validator;
|
||||
|
||||
use Utopia\Validator;
|
||||
|
||||
/**
|
||||
* Email
|
||||
*
|
||||
* Validate that an variable is a valid email address
|
||||
*
|
||||
* @package Utopia\Validator
|
||||
*/
|
||||
class Email extends Validator
|
||||
{
|
||||
protected bool $allowEmpty;
|
||||
|
||||
public function __construct(bool $allowEmpty = false)
|
||||
{
|
||||
$this->allowEmpty = $allowEmpty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Description
|
||||
*
|
||||
* Returns validator description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Value must be a valid email address';
|
||||
}
|
||||
|
||||
/**
|
||||
* Is valid
|
||||
*
|
||||
* Validation will pass when $value is valid email address.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid($value): bool
|
||||
{
|
||||
if ($this->allowEmpty && \strlen($value) === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!\filter_var($value, FILTER_VALIDATE_EMAIL)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is array
|
||||
*
|
||||
* Function will return true if object is array.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isArray(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Type
|
||||
*
|
||||
* Returns validator type.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return self::TYPE_STRING;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -4,7 +4,7 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attribu
|
||||
|
||||
use Appwrite\Event\Database as EventDatabase;
|
||||
use Appwrite\Event\Event;
|
||||
use Appwrite\Network\Validator\Email;
|
||||
use Utopia\Emails\Validator\Email;
|
||||
use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action;
|
||||
use Appwrite\SDK\AuthType;
|
||||
use Appwrite\SDK\Deprecated;
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Email;
|
||||
|
||||
use Appwrite\Event\Event;
|
||||
use Appwrite\Network\Validator\Email;
|
||||
use Utopia\Emails\Validator\Email;
|
||||
use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action;
|
||||
use Appwrite\SDK\AuthType;
|
||||
use Appwrite\SDK\ContentType;
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\Email;
|
||||
|
||||
use Appwrite\Network\Validator\Email;
|
||||
use Utopia\Emails\Validator\Email;
|
||||
use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Email\Create as EmailCreate;
|
||||
use Appwrite\SDK\AuthType;
|
||||
use Appwrite\SDK\Method;
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Columns\Email;
|
||||
|
||||
use Appwrite\Network\Validator\Email;
|
||||
use Utopia\Emails\Validator\Email;
|
||||
use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Email\Update as EmailUpdate;
|
||||
use Appwrite\SDK\AuthType;
|
||||
use Appwrite\SDK\ContentType;
|
||||
|
||||
@@ -7,7 +7,7 @@ use Appwrite\Event\Event;
|
||||
use Appwrite\Event\Mail;
|
||||
use Appwrite\Event\Messaging;
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\Network\Validator\Email as EmailValidator;
|
||||
use Utopia\Emails\Validator\Email as EmailValidator;
|
||||
use Appwrite\Platform\Action;
|
||||
use Appwrite\SDK\AuthType;
|
||||
use Appwrite\SDK\Method;
|
||||
|
||||
@@ -5,8 +5,8 @@ namespace Appwrite\Utopia\Database\Validator;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Validator\Datetime as DatetimeValidator;
|
||||
use Utopia\Database\Validator\Key;
|
||||
use Utopia\Emails\Validator\Email;
|
||||
use Utopia\Validator;
|
||||
use Utopia\Validator\Email;
|
||||
use Utopia\Validator\IP;
|
||||
use Utopia\Validator\Range;
|
||||
use Utopia\Validator\Text;
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Utopia PHP Framework
|
||||
*
|
||||
* @package Framework
|
||||
* @subpackage Tests
|
||||
*
|
||||
* @link https://github.com/utopia-php/framework
|
||||
* @author Appwrite Team <team@appwrite.io>
|
||||
* @version 1.0 RC4
|
||||
* @license The MIT License (MIT) <http://www.opensource.org/licenses/mit-license.php>
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\Network\Validators;
|
||||
|
||||
use Appwrite\Network\Validator\Email;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class EmailTest extends TestCase
|
||||
{
|
||||
protected ?Email $email = null;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->email = new Email();
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
$this->email = null;
|
||||
}
|
||||
|
||||
public function testIsValid(): void
|
||||
{
|
||||
$this->assertEquals(true, $this->email->isValid('email@domain.com'));
|
||||
$this->assertEquals(true, $this->email->isValid('firstname.lastname@domain.com'));
|
||||
$this->assertEquals(true, $this->email->isValid('email@subdomain.domain.com'));
|
||||
$this->assertEquals(true, $this->email->isValid('firstname+lastname@domain.com'));
|
||||
$this->assertEquals(true, $this->email->isValid('email@[123.123.123.123]'));
|
||||
$this->assertEquals(true, $this->email->isValid('"email"@domain.com'));
|
||||
$this->assertEquals(true, $this->email->isValid('1234567890@domain.com'));
|
||||
$this->assertEquals(true, $this->email->isValid('email@domain-one.com'));
|
||||
$this->assertEquals(true, $this->email->isValid('_______@domain.com'));
|
||||
$this->assertEquals(true, $this->email->isValid('email@domain.name'));
|
||||
$this->assertEquals(true, $this->email->isValid('email@domain.co.jp'));
|
||||
$this->assertEquals(true, $this->email->isValid('firstname-lastname@domain.com'));
|
||||
$this->assertEquals(false, $this->email->isValid(false));
|
||||
$this->assertEquals(false, $this->email->isValid(['string', 'string']));
|
||||
$this->assertEquals(false, $this->email->isValid(1));
|
||||
$this->assertEquals(false, $this->email->isValid(1.2));
|
||||
$this->assertEquals(false, $this->email->isValid('plainaddress')); // Missing @ sign and domain
|
||||
$this->assertEquals(false, $this->email->isValid('@domain.com')); // Missing username
|
||||
$this->assertEquals(false, $this->email->isValid('#@%^%#$@#$@#.com')); // Garbage
|
||||
$this->assertEquals(false, $this->email->isValid('Joe Smith <email@domain.com>')); // Encoded html within email is invalid
|
||||
$this->assertEquals(false, $this->email->isValid('email.domain.com')); // Missing @
|
||||
$this->assertEquals(false, $this->email->isValid('email@domain@domain.com')); // Two @ sign
|
||||
$this->assertEquals(false, $this->email->isValid('.email@domain.com')); // Leading dot in address is not allowed
|
||||
$this->assertEquals(false, $this->email->isValid('email.@domain.com')); // Trailing dot in address is not allowed
|
||||
$this->assertEquals(false, $this->email->isValid('email..email@domain.com')); // Multiple dots
|
||||
$this->assertEquals(false, $this->email->isValid('あいうえお@domain.com')); // Unicode char as address
|
||||
$this->assertEquals(false, $this->email->isValid('email@domain.com (Joe Smith)')); // Text followed email is not allowed
|
||||
$this->assertEquals(false, $this->email->isValid('email@domain')); // Missing top level domain (.com/.net/.org/etc)
|
||||
$this->assertEquals(false, $this->email->isValid('email@-domain.com')); // Leading dash in front of domain is invalid
|
||||
$this->assertEquals(false, $this->email->isValid('email@111.222.333.44444')); // Invalid IP format
|
||||
$this->assertEquals(false, $this->email->isValid('email@domain..com')); // Multiple dot in the domain portion is invalid
|
||||
$this->assertEquals($this->email->getType(), 'string');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user