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/56' into develop
Browse files Browse the repository at this point in the history
Forward port #56
  • Loading branch information
weierophinney committed Feb 17, 2016
2 parents ee1aece + f2ac0d9 commit b006d5b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ All notable changes to this project will be documented in this file, in reverse
- [#54](https://github.com/zendframework/zend-validator/pull/54) fixes the IP
address detection in the `Hostname` validator to ensure that IPv6 is detected
correctly.
- [#56](https://github.com/zendframework/zend-validator/pull/56) updates the
regexes used by the `IP` validator when comparing ipv4 addresses to ensure a
literal `.` is tested between network segments.

## 2.5.3 - 2015-09-03

Expand Down
6 changes: 3 additions & 3 deletions src/Ip.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ public function isValid($value)
*/
protected function validateIPv4($value)
{
if (preg_match('/^([01]{8}.){3}[01]{8}\z/i', $value)) {
if (preg_match('/^([01]{8}\.){3}[01]{8}\z/i', $value)) {
// binary format 00000000.00000000.00000000.00000000
$value = bindec(substr($value, 0, 8)) . '.' . bindec(substr($value, 9, 8)) . '.'
. bindec(substr($value, 18, 8)) . '.' . bindec(substr($value, 27, 8));
} elseif (preg_match('/^([0-9]{3}.){3}[0-9]{3}\z/i', $value)) {
} elseif (preg_match('/^([0-9]{3}\.){3}[0-9]{3}\z/i', $value)) {
// octet format 777.777.777.777
$value = (int) substr($value, 0, 3) . '.' . (int) substr($value, 4, 3) . '.'
. (int) substr($value, 8, 3) . '.' . (int) substr($value, 12, 3);
} elseif (preg_match('/^([0-9a-f]{2}.){3}[0-9a-f]{2}\z/i', $value)) {
} elseif (preg_match('/^([0-9a-f]{2}\.){3}[0-9a-f]{2}\z/i', $value)) {
// hex format ff.ff.ff.ff
$value = hexdec(substr($value, 0, 2)) . '.' . hexdec(substr($value, 3, 2)) . '.'
. hexdec(substr($value, 6, 2)) . '.' . hexdec(substr($value, 9, 2));
Expand Down
28 changes: 26 additions & 2 deletions test/IpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,31 @@ public function testGetMessages()
public function testEqualsMessageTemplates()
{
$validator = $this->validator;
$this->assertAttributeEquals($validator->getOption('messageTemplates'),
'messageTemplates', $validator);
$this->assertAttributeEquals(
$validator->getOption('messageTemplates'),
'messageTemplates',
$validator
);
}

public function invalidIpV4Addresses()
{
return [
'all-numeric' => ['111111111111'],
'first-quartet' => ['111.111111111'],
'first-octet' => ['111111.111111'],
'last-quartet' => ['111111111.111'],
'first-second-quartet' => ['111.111.111111'],
'first-fourth-quartet' => ['111.111111.111'],
'third-fourth-quartet' => ['111111.111.111'],
];
}

/**
* @dataProvider invalidIpV4Addresses
*/
public function testIpV4ValidationShouldFailForIpV4AddressesMissingQuartets($address)
{
$this->assertFalse($this->validator->isValid($address));
}
}

0 comments on commit b006d5b

Please sign in to comment.