Edit report at http://pear.php.net/bugs/bug.php?id=17662&edit=1
ID: 17662
Updated by: mj@php.net
Reported By: hm2k at php dot net
Summary: Is there really need for a regex or does a PHP
function do the trick?
-Status: Assigned
+Status: Wont fix
Type: Feature/Change Request
Package: Net_CheckIP
Package Version: SVN
PHP Version: Irrelevant
Assigned To: mj
Roadmap Versions:
New Comment:
-Status: Assigned
+Status: Wont fix
James,
again, what you suggested will not work.
<?php
$var = "+127";
var_dump(!is_numeric($var) || ceil($var) != $var);
?>
will result in
bool(false)
Thus with your patch the input "+127.0.0.1" will yield a positive return
value, which clearly is bogus. Using ctype_digit() will probably work,
but I'm hesitating to go this route because I don't intend to add an
extension dependency.
I suggest you stop investing so much of your time in this old package
and focus on Net_CheckIP2 instead. Thanks.
Previous Comments:
------------------------------------------------------------------------
[2011-02-28 21:19:51] hm2k
-Status: Wont fix
+Status: Assigned
The idea here is to completely get rid of the preg_match, which isn't
required.
- if (!preg_match("/^[0-9]+$/", $oct[$i])) {
+ if (!is_numeric($oct[$i]) || ceil($oct[$i]) != $oct[$i]) {
------------------------------------------------------------------------
[2011-02-28 20:10:22] mj
-Status: Assigned
+Status: Wont fix
Using is_int() is not right here because it only works if the given
variable is acutally of type int already:
<?php
var_dump(is_int("123"));
var_dump(is_int(123));
?>
will actually print
bool(false)
bool(true)
If we were to change something in the really really ancient code, we
could completely get rid of the preg_match() check, because the next
check will work just fine for rejecting any input that is not an integer
between 0 and 255.
------------------------------------------------------------------------
[2011-02-16 14:03:21] hm2k
-Assigned To:
+Assigned To: mj
------------------------------------------------------------------------
[2011-02-15 17:46:42] hm2k
Patch attached.
I see no reason not to include this improvement.
------------------------------------------------------------------------
[2011-02-15 17:46:10] hm2k
Added #patch bug:17662;patch:net-checkip-no-regex;revision:1297791970;.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://pear.php.net/bugs/bug.php?id=17662
[PEAR-BUG] Req #17662 [Opn]: Is there really need for a regex or does a PHP function do the trick?
Discussion Overview
| group | pear-bugs |
| categories | php |
| posted | Feb 15, '11 at 4:44p |
| active | Feb 28, '11 at 8:52p |
| posts | 5 |
| users | 2 |
| website | pear.php.net |
