Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions library/Zend/Validator/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}$/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}$/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}$/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
6 changes: 6 additions & 0 deletions tests/ZendTest/Validator/IpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ public function testIPv4AddressNotations()
'a0.b0.c0.d0' => true,
'g0.00.00.00' => false,
'g0.00.00.00:80' => false,

// new lines should not accept
"00000001.00000010.00000011.00000100\n" => false,
"001.002.003.004\n" => false,
"a0.b0.c0.d0\n" => false,

);

foreach ($ips as $ip => $expectedOutcome) {
Expand Down