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

Commit d8d06c2

Browse files
committed
Merge pull request #241 from andreasschroth/andreasschroth_fix_issue_240
Skip further checks in case of empty domain part
2 parents fdaedea + 081fd6b commit d8d06c2

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Hostname.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,6 +2092,13 @@ public function isValid($value)
20922092
}
20932093
}
20942094

2095+
// Skip following checks if domain part is empty, as it definitely is not a valid hostname then
2096+
if ($domainPart === '') {
2097+
$this->error(self::INVALID_HOSTNAME);
2098+
$status = false;
2099+
break 2;
2100+
}
2101+
20952102
// Check dash (-) does not start, end or appear in 3rd and 4th positions
20962103
if ($utf8StrWrapper->strpos($domainPart, '-') === 0
20972104
|| ($utf8StrWrapper->strlen($domainPart) > 2

test/HostnameTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,4 +701,10 @@ public function testValidBizHostname()
701701
$validator = new Hostname();
702702
$this->assertTrue($validator->isValid('google.biz'));
703703
}
704+
705+
public function testHostnameWithEmptyDomainPart()
706+
{
707+
$validator = new Hostname();
708+
$this->assertFalse($validator->isValid('.com'));
709+
}
704710
}

0 commit comments

Comments
 (0)