diff --git a/src/Validator/Domain.php b/src/Validator/Domain.php index aea0a21c..54c2eb50 100644 --- a/src/Validator/Domain.php +++ b/src/Validator/Domain.php @@ -45,11 +45,7 @@ public function isValid($value): bool return false; } - if (\filter_var($value, FILTER_VALIDATE_DOMAIN) === false) { - return false; - } - - return true; + return \filter_var($value, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) !== false; } /** diff --git a/tests/Validator/DomainTest.php b/tests/Validator/DomainTest.php index ca14a20e..2ed7c594 100644 --- a/tests/Validator/DomainTest.php +++ b/tests/Validator/DomainTest.php @@ -1,4 +1,5 @@ assertEquals(true, $this->domain->isValid('example.com')); $this->assertEquals(true, $this->domain->isValid('subdomain.example.com')); $this->assertEquals(true, $this->domain->isValid('subdomain.example-app.com')); - $this->assertEquals(true, $this->domain->isValid('subdomain.example_app.com')); $this->assertEquals(true, $this->domain->isValid('subdomain-new.example.com')); - $this->assertEquals(true, $this->domain->isValid('subdomain_new.example.com')); $this->assertEquals(true, $this->domain->isValid('localhost')); $this->assertEquals(true, $this->domain->isValid('example.io')); $this->assertEquals(true, $this->domain->isValid('example.org')); $this->assertEquals(true, $this->domain->isValid('example.org')); + $this->assertEquals(false, $this->domain->isValid('example.com/path')); + $this->assertEquals(false, $this->domain->isValid('subdomain_new.example.com')); + $this->assertEquals(false, $this->domain->isValid('subdomain.example_app.com')); + $this->assertEquals(false, $this->domain->isValid('http://example.com')); + $this->assertEquals(false, $this->domain->isValid('https://example.com')); + $this->assertEquals(false, $this->domain->isValid('ftp://example.com')); $this->assertEquals(false, $this->domain->isValid(false)); $this->assertEquals(false, $this->domain->isValid('.')); $this->assertEquals(false, $this->domain->isValid('..'));