Failure

User tests: Successful: Unsuccessful:

avatar fitorec
fitorec
15 Feb 2013

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?

avatar fitorec fitorec - open - 15 Feb 2013
avatar mbabker
mbabker - comment - 16 Feb 2013

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.

avatar fitorec
fitorec - comment - 16 Feb 2013

Yep, that's fine :blush:.

avatar fitorec fitorec - reference | - 16 Feb 13
avatar fitorec
fitorec - comment - 16 Feb 2013

I just made the change in:

joomla/joomla-platform#1833

avatar nicksavov
nicksavov - comment - 4 May 2013

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!

avatar Narimm Narimm - reference | - 26 Nov 13
avatar wilsonge
wilsonge - comment - 4 Mar 2014

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

avatar SniperSister
SniperSister - comment - 22 Mar 2014

@wilsonge why do you think that using the filter_var function is a b/c breaker? It's only changing the internal way how the method works?

avatar wilsonge
wilsonge - comment - 22 Mar 2014

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)

avatar SniperSister
SniperSister - comment - 22 Mar 2014

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.

avatar roland-d
roland-d - comment - 11 May 2014

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.

avatar wilsonge wilsonge - reference | - 26 Jul 14
avatar brianteeman
brianteeman - comment - 26 Jul 2014

Closed in favour of #3990

avatar brianteeman brianteeman - close - 26 Jul 2014

Add a Comment

Login with GitHub to post a comment