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

Commit 7919c2e

Browse files
committed
Merge branch 'hotfix/54'
Close #54
2 parents 07e6e4c + 126e679 commit 7919c2e

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ All notable changes to this project will be documented in this file, in reverse
2727
- [#52](https://github.com/zendframework/zend-validator/pull/52) updates the
2828
`Barcode` validator to cast empty options passed to the constructor to an
2929
empty array, fixing type mismatch errors.
30+
- [#54](https://github.com/zendframework/zend-validator/pull/54) fixes the IP
31+
address detection in the `Hostname` validator to ensure that IPv6 is detected
32+
correctly.
3033

3134
## 2.5.3 - 2015-09-03
3235

src/Hostname.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,8 @@ public function isValid($value)
16711671

16721672
$this->setValue($value);
16731673
// Check input against IP address schema
1674-
if (preg_match('/^[0-9a-f:.]*$/i', $value)
1674+
if (((preg_match('/^[0-9.]*$/', $value) && strpos($value, '.') !== false)
1675+
|| (preg_match('/^[0-9a-f:.]*$/i', $value) && strpos($value, ':') !== false))
16751676
&& $this->getIpValidator()->setTranslator($this->getTranslator())->isValid($value)
16761677
) {
16771678
if (!($this->getAllow() & self::ALLOW_IP)) {

test/HostnameTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,4 +527,10 @@ public function testEqualsMessageVariables()
527527
$validator = $this->validator;
528528
$this->assertAttributeEquals($validator->getOption('messageVariables'), 'messageVariables', $validator);
529529
}
530+
531+
public function testHostnameWithOnlyIpChars()
532+
{
533+
$validator = new Hostname();
534+
$this->assertTrue($validator->isValid('cafecafe.de'));
535+
}
530536
}

0 commit comments

Comments
 (0)