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

Commit 280b3c1

Browse files
committed
Merge pull request #54 from rapidsoft-de/fix-hostname-with-only-ip-chars
Prevent IP validation from being triggered for hostnames that only contain IP chars
2 parents 07e6e4c + 7c5370e commit 280b3c1

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

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)