Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge pull request #241 from andreasschroth/andreasschroth_fix_issue_240
Browse files Browse the repository at this point in the history
Skip further checks in case of empty domain part
  • Loading branch information
weierophinney committed Dec 13, 2018
2 parents fdaedea + 081fd6b commit d8d06c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Hostname.php
Original file line number Diff line number Diff line change
Expand Up @@ -2092,6 +2092,13 @@ public function isValid($value)
}
}

// Skip following checks if domain part is empty, as it definitely is not a valid hostname then
if ($domainPart === '') {
$this->error(self::INVALID_HOSTNAME);
$status = false;
break 2;
}

// Check dash (-) does not start, end or appear in 3rd and 4th positions
if ($utf8StrWrapper->strpos($domainPart, '-') === 0
|| ($utf8StrWrapper->strlen($domainPart) > 2
Expand Down
6 changes: 6 additions & 0 deletions test/HostnameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -701,4 +701,10 @@ public function testValidBizHostname()
$validator = new Hostname();
$this->assertTrue($validator->isValid('google.biz'));
}

public function testHostnameWithEmptyDomainPart()
{
$validator = new Hostname();
$this->assertFalse($validator->isValid('.com'));
}
}

0 comments on commit d8d06c2

Please sign in to comment.