The top voted answer for validating IP addresses here (which is a regex, so automatically unfavourable) returns false if you give it an IP address with 4 or more zeros in a single octet.
Note that it passes with 3 or less, which in my opinion, automatically indicates code smell due to arbitrary inconsistency (after all it's not base 8 and so there is nothing special about 3 in base 10). Nevertheless, surprisingly the apache commons utility InetAddressValidator
also has this behaviour (at least it only uses regex for the splitting!).
Observe (using Scala REPL):
scala> new InetAddressValidator().isValidInet4Address("000.0.0.0")
res0: Boolean = true
scala> new InetAddressValidator().isValidInet4Address("0000.0.0.0")
res1: Boolean = false
Now this answer would return true, as it's using parseInt
in a loop which makes no arbitrary distinction between numbers of zeros.
So is it valid? If it is valid then this indicates a bug in Apache Commons library and the said regex, and if it is NOT valid then please provide a link to something that proves it.