mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
fix: added space validation
This commit is contained in:
@@ -19,6 +19,9 @@ class AppwriteNetworkDomain extends Validator
|
||||
if (!is_string($value) || empty($value)) {
|
||||
return true;
|
||||
}
|
||||
if (\preg_match('/\s/', $value)) {
|
||||
return false;
|
||||
}
|
||||
if (\str_starts_with($value, '.')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -77,22 +77,30 @@ class AppwriteNetworkDomainTest extends TestCase
|
||||
$this->assertEquals(true, $this->validator->isValid('foo.bar.baz.example.com'));
|
||||
}
|
||||
|
||||
public function testEdgeCases(): void
|
||||
{
|
||||
// Empty and invalid values should pass (let other validators handle them)
|
||||
$this->assertEquals(true, $this->validator->isValid(''));
|
||||
$this->assertEquals(true, $this->validator->isValid(null));
|
||||
$this->assertEquals(true, $this->validator->isValid(false));
|
||||
$this->assertEquals(true, $this->validator->isValid(123));
|
||||
$this->assertEquals(true, $this->validator->isValid([]));
|
||||
public function testEdgeCases(): void
|
||||
{
|
||||
// Empty and invalid values should pass (let other validators handle them)
|
||||
$this->assertEquals(true, $this->validator->isValid(''));
|
||||
$this->assertEquals(true, $this->validator->isValid(null));
|
||||
$this->assertEquals(true, $this->validator->isValid(false));
|
||||
$this->assertEquals(true, $this->validator->isValid(123));
|
||||
$this->assertEquals(true, $this->validator->isValid([]));
|
||||
|
||||
// Just the root domain (unlikely but should be valid)
|
||||
$this->assertEquals(true, $this->validator->isValid('appwrite.network'));
|
||||
// Just the root domain (unlikely but should be valid)
|
||||
$this->assertEquals(true, $this->validator->isValid('appwrite.network'));
|
||||
|
||||
// Domain with trailing/leading dots
|
||||
$this->assertEquals(false, $this->validator->isValid('api.test.appwrite.network.'));
|
||||
$this->assertEquals(false, $this->validator->isValid('.api.test.appwrite.network'));
|
||||
}
|
||||
// Domain with trailing/leading dots
|
||||
$this->assertEquals(false, $this->validator->isValid('api.test.appwrite.network.'));
|
||||
$this->assertEquals(false, $this->validator->isValid('.api.test.appwrite.network'));
|
||||
|
||||
// Domains with spaces should be invalid
|
||||
$this->assertEquals(false, $this->validator->isValid('my app.appwrite.network'));
|
||||
$this->assertEquals(false, $this->validator->isValid('api .appwrite.network'));
|
||||
$this->assertEquals(false, $this->validator->isValid(' api.appwrite.network'));
|
||||
$this->assertEquals(false, $this->validator->isValid('api.appwrite.network '));
|
||||
$this->assertEquals(false, $this->validator->isValid('api.app write.network'));
|
||||
$this->assertEquals(false, $this->validator->isValid("api\tapp.appwrite.network"));
|
||||
}
|
||||
|
||||
public function testValidatorProperties(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user