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

Commit

Permalink
Merge branch 'hotfix/241'
Browse files Browse the repository at this point in the history
Close #241
Fixes #240
  • Loading branch information
weierophinney committed Dec 13, 2018
2 parents fdaedea + 6f97afe commit 9adc62f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 2.10.3 - TBD
## 2.10.3 - 2018-12-13

### Added

Expand All @@ -22,6 +22,9 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- [#241](https://github.com/zendframework/zend-validator/pull/241) has the `Hostname` validator return an invalid result early when an empty
domain segment is detected.

- [#232](https://github.com/zendframework/zend-validator/pull/232) updates the `Hostname` validator to allow underscores in subdomains.

- [#218](https://github.com/zendframework/zend-validator/pull/218) fixes a precision issue with the `Step` validator.
Expand Down
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 9adc62f

Please sign in to comment.