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

Commit d931079

Browse files
committed
Merge branch 'hotfix/56'
Close #56
2 parents 7919c2e + f2ac0d9 commit d931079

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ All notable changes to this project will be documented in this file, in reverse
3030
- [#54](https://github.com/zendframework/zend-validator/pull/54) fixes the IP
3131
address detection in the `Hostname` validator to ensure that IPv6 is detected
3232
correctly.
33+
- [#56](https://github.com/zendframework/zend-validator/pull/56) updates the
34+
regexes used by the `IP` validator when comparing ipv4 addresses to ensure a
35+
literal `.` is tested between network segments.
3336

3437
## 2.5.3 - 2015-09-03
3538

src/Ip.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ public function isValid($value)
9797
*/
9898
protected function validateIPv4($value)
9999
{
100-
if (preg_match('/^([01]{8}.){3}[01]{8}\z/i', $value)) {
100+
if (preg_match('/^([01]{8}\.){3}[01]{8}\z/i', $value)) {
101101
// binary format 00000000.00000000.00000000.00000000
102102
$value = bindec(substr($value, 0, 8)) . '.' . bindec(substr($value, 9, 8)) . '.'
103103
. bindec(substr($value, 18, 8)) . '.' . bindec(substr($value, 27, 8));
104-
} elseif (preg_match('/^([0-9]{3}.){3}[0-9]{3}\z/i', $value)) {
104+
} elseif (preg_match('/^([0-9]{3}\.){3}[0-9]{3}\z/i', $value)) {
105105
// octet format 777.777.777.777
106106
$value = (int) substr($value, 0, 3) . '.' . (int) substr($value, 4, 3) . '.'
107107
. (int) substr($value, 8, 3) . '.' . (int) substr($value, 12, 3);
108-
} elseif (preg_match('/^([0-9a-f]{2}.){3}[0-9a-f]{2}\z/i', $value)) {
108+
} elseif (preg_match('/^([0-9a-f]{2}\.){3}[0-9a-f]{2}\z/i', $value)) {
109109
// hex format ff.ff.ff.ff
110110
$value = hexdec(substr($value, 0, 2)) . '.' . hexdec(substr($value, 3, 2)) . '.'
111111
. hexdec(substr($value, 6, 2)) . '.' . hexdec(substr($value, 9, 2));

test/IpTest.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,31 @@ public function testGetMessages()
367367
public function testEqualsMessageTemplates()
368368
{
369369
$validator = $this->validator;
370-
$this->assertAttributeEquals($validator->getOption('messageTemplates'),
371-
'messageTemplates', $validator);
370+
$this->assertAttributeEquals(
371+
$validator->getOption('messageTemplates'),
372+
'messageTemplates',
373+
$validator
374+
);
375+
}
376+
377+
public function invalidIpV4Addresses()
378+
{
379+
return [
380+
'all-numeric' => ['111111111111'],
381+
'first-quartet' => ['111.111111111'],
382+
'first-octet' => ['111111.111111'],
383+
'last-quartet' => ['111111111.111'],
384+
'first-second-quartet' => ['111.111.111111'],
385+
'first-fourth-quartet' => ['111.111111.111'],
386+
'third-fourth-quartet' => ['111111.111.111'],
387+
];
388+
}
389+
390+
/**
391+
* @dataProvider invalidIpV4Addresses
392+
*/
393+
public function testIpV4ValidationShouldFailForIpV4AddressesMissingQuartets($address)
394+
{
395+
$this->assertFalse($this->validator->isValid($address));
372396
}
373397
}

0 commit comments

Comments
 (0)