Skip to content

Commit

Permalink
Merge pull request #67 from samsonasik/possible-solution-for-8
Browse files Browse the repository at this point in the history
Possible fixes #8 compilation failed regex too large
  • Loading branch information
weierophinney authored Jan 6, 2021
2 parents 0a49388 + 4a808c8 commit d7b823f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Hostname.php
Original file line number Diff line number Diff line change
Expand Up @@ -1977,6 +1977,14 @@ public function isValid($value)
return true;
}

// Handle Regex compilation failure that may happen on .biz domain with has @ character, eg: [email protected]
// Technically, hostname with '@' character is invalid, so mark as invalid immediately
// @see https://github.com/laminas/laminas-validator/issues/8
if (strpos($value, '@') !== false) {
$this->error(self::INVALID_HOSTNAME);
return false;
}

// Local hostnames are allowed to be partial (ending '.')
if ($this->getAllow() & self::ALLOW_LOCAL) {
if (substr($value, -1) === '.') {
Expand Down
6 changes: 6 additions & 0 deletions test/HostnameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,12 @@ public function testValidBizHostname()
$this->assertTrue($validator->isValid('google.biz'));
}

public function testInValidHostnameWithAt()
{
$validator = new Hostname();
$this->assertFalse($validator->isValid('[email protected]'));
}

public function testHostnameWithEmptyDomainPart()
{
$validator = new Hostname();
Expand Down

0 comments on commit d7b823f

Please sign in to comment.