From 3ff3b2224b6d1bdec4a3cf4d40e7b34a40b52b77 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 27 Apr 2026 16:15:59 +0000 Subject: [PATCH 1/2] feat: add allowEmpty support to Domain validator Agent-Logs-Url: https://github.com/utopia-php/validators/sessions/c7c6148a-382c-495e-89ca-96ed85804048 Co-authored-by: Meldiron <19310830+Meldiron@users.noreply.github.com> --- src/Validator/Domain.php | 7 ++++++- tests/Validator/DomainTest.php | 25 ++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/Validator/Domain.php b/src/Validator/Domain.php index 535b681..9766263 100644 --- a/src/Validator/Domain.php +++ b/src/Validator/Domain.php @@ -18,7 +18,8 @@ class Domain extends Validator */ public function __construct( protected array $restrictions = [], - protected bool $hostnames = true + protected bool $hostnames = true, + protected bool $allowEmpty = false ) { } @@ -64,6 +65,10 @@ public function getDescription(): string */ public function isValid($value): bool { + if ($this->allowEmpty && $value === '') { + return true; + } + if (empty($value)) { return false; } diff --git a/tests/Validator/DomainTest.php b/tests/Validator/DomainTest.php index 9ec30c8..47d38aa 100644 --- a/tests/Validator/DomainTest.php +++ b/tests/Validator/DomainTest.php @@ -120,7 +120,30 @@ public function testInvalidDomainsWithHostnamesFalse() $this->assertSame(true, $permissiveValidator->isValid('example.com/path')); // Path } - public function testRestrictions() + /** + * Test allowEmpty parameter + */ + public function testAllowEmpty() + { + // By default, empty string is invalid + $this->assertSame(false, $this->domain->isValid('')); + + // With allowEmpty=true, empty string is valid + $domainAllowEmpty = new Domain([], true, true); + $this->assertSame(true, $domainAllowEmpty->isValid('')); + + // null is still invalid even with allowEmpty=true + $this->assertSame(false, $domainAllowEmpty->isValid(null)); + + // Valid domains still pass with allowEmpty=true + $this->assertSame(true, $domainAllowEmpty->isValid('example.com')); + $this->assertSame(true, $domainAllowEmpty->isValid('subdomain.example.com')); + + // Invalid domains still fail with allowEmpty=true + $this->assertSame(false, $domainAllowEmpty->isValid('invalid..domain')); + $this->assertSame(false, $domainAllowEmpty->isValid(1)); + } + { $validator = new Domain([ Domain::createRestriction('appwrite.network', 3, ['preview-', 'branch-']), From da6033b2ebb59fe0e9bcc474a3e68b6683e927c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 27 Apr 2026 18:26:58 +0200 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- tests/Validator/DomainTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Validator/DomainTest.php b/tests/Validator/DomainTest.php index 47d38aa..ecd25fc 100644 --- a/tests/Validator/DomainTest.php +++ b/tests/Validator/DomainTest.php @@ -144,6 +144,7 @@ public function testAllowEmpty() $this->assertSame(false, $domainAllowEmpty->isValid(1)); } + public function testRestrictions() { $validator = new Domain([ Domain::createRestriction('appwrite.network', 3, ['preview-', 'branch-']),