ip-address
ip-address copied to clipboard
Difference between isCorrent and isValid
The semantics of isCorrect
and isValid
in Address4
and Address6
are not obvious and should be part of the documentation.
agreed, “correctness” as a concept was really only given much thought for v6 but it can also be applied to v4, I’ll give that some thought
Sent from my phone.
On Feb 23, 2018, at 02:24, Markus Fuchs [email protected] wrote:
The semantics of isCorrect and isValid in Address4 and Address6 are not obvious and should be part of the documentation.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
So, what is the difference between the two methods? I'm trying to figure out which one to use.
isValid()
returns true
if the address is valid, meaning it parses successfully/does not contain errors
isCorrect()
should probably be renamed to avoid confusion; isPreferredForm()
probably better captures the meaning...
an address like ffff:000f::
is valid but not "correct" or the "preferred form" because it contains leading zeroes, in this example (the "preferred form" would be ffff:f::
)
more information on IPv6 preferred form here: https://tools.ietf.org/html/rfc5952#page-10
similarly for IPv4 an address like 192.168.000.001
is valid but not correct/preferred (192.168.0.1
would be the correct/preferred form)
make more sense?
in the code I believe I just compare the input string to the result of correctForm()
and return false
if they don't match
Thanks! Makes perfect sense!