User tests: Successful: Unsuccessful:
I realized that IPs are not entirely correct validating, for example:
<?php
$domain = '192.23.243.23.2';
$regex = '/^[0-9\.]+$/';
preg_match($regex, $domain);
//TRUE
One option is to change the regular expression to catch four numbers separated by a dot:
<?php
$domain = '192.23.243.23.2';
$regex = '/^([0-9]{1,3}\.){3}[1-9]+$/';
preg_match($regex, $domain);
//FALSE
Another problem is that soon there will be more IPv6 addresses so we would have to change the regular expression to something like:
<?php
$regex = '/^(([0-9]{1,3}\.){3}[1-9]+)|([0-9a-f]*::[0-9]+)$/';
Fortunately PHP5 has a function (inet_pton) that returns false if the IP address is wrong, I think this is a better solution.
What do you think?
Yep, that's fine .
I just made the change in:
Thanks for coding this, Miguel! There's been a recent change where the CMS has reabsorbed the platform and the platform transitioned into the new framework. Long story short, we can take this pull request directly now :)
While we’re transitioning to a new integrated tracker, could you report the issue on our current main tracker at JoomlaCode and cross-reference each with a link to the other? Here’s the process for reporting on the other tracker:
http://docs.joomla.org/Filing_bugs_and_issues
Alternatively, let me know if you’d like me to create it for you and I can go ahead and do that.
Thanks in advance and thanks again for coding this, Miguel!
I think we should consider using the php standard that got used in the platform/framework (see the platform PR) but it is a b/c breaker technically. @mbabker is this something you would be willing to accept for 3.3? Or would you rather a technical fix for now until 4.0 when we move to the php function
because it gives different results to what we are getting with the function as is (see the comments on the platform PR here: joomla/joomla-platform#1833)
Oh yeah, ok, true, didn't ready through the framework pr comments. So in that case, I would vote for fixing this by using inet_pton for 3.x and than changing to filter_var for 4.0 too.
Looking at the code change, should we suppress errors with the @ ? This is usually bad coding :) The function doesn't throw any errors, it simply returns false if there is a non-valid IP address passed.
Thanks for the pull request. Since this file is part of the Joomla Platform, would you mind proposing your change there? This ensures that the primary source gets updated as well as the CMS instance.