Skip to content

Commit 005cef0

Browse files
authored
Merge pull request #2540 from nowackipawel/patch-80
valid_ip removed $data which was causing exception
2 parents 2e73061 + 8858f4d commit 005cef0

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

system/Validation/FormatRules.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,16 +321,19 @@ public function valid_emails(string $str = null): bool
321321
}
322322

323323
/**
324-
* Validate an IP address
324+
* Validate an IP address (human readable format or binary string - inet_pton)
325325
*
326326
* @param string $ip IP Address
327327
* @param string $which IP protocol: 'ipv4' or 'ipv6'
328-
* @param array $data
329328
*
330329
* @return boolean
331330
*/
332-
public function valid_ip(string $ip = null, string $which = null, array $data): bool
333-
{
331+
public function valid_ip(string $ip = null, string $which = null): bool
332+
{
333+
if(empty($ip))
334+
{
335+
return false;
336+
}
334337
switch (strtolower($which))
335338
{
336339
case 'ipv4':
@@ -344,7 +347,7 @@ public function valid_ip(string $ip = null, string $which = null, array $data):
344347
break;
345348
}
346349

347-
return (bool) filter_var($ip, FILTER_VALIDATE_IP, $which);
350+
return (bool) filter_var($ip, FILTER_VALIDATE_IP, $which) || (!ctype_print($ip) && (bool) filter_var(inet_ntop($ip), FILTER_VALIDATE_IP, $which));
348351
}
349352

350353
/**

0 commit comments

Comments
 (0)