Skip to content

Commit

Permalink
chore: use FILTER_FLAG_HOSTNAME, more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
loks0n committed Nov 13, 2023
1 parent f37ba14 commit 641a7a0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
6 changes: 1 addition & 5 deletions src/Validator/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,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;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions tests/Validator/DomainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ public function testIsValid()
$this->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'));
Expand Down

0 comments on commit 641a7a0

Please sign in to comment.