beaugunderson / ip-address

đź’» a library for parsing and manipulating IPv4 and IPv6 addresses in JavaScript
http://ip-address.js.org/
MIT License
580 stars 73 forks source link

0:0:0:0:0:0:0:1 and 0:0:0:0:0:0:0:0 invalid #121

Closed zctya closed 4 years ago

zctya commented 4 years ago

WX20201027-103509

beaugunderson commented 4 years ago

the fact that you got an Address6 and not an exception means it’s valid—can you help me understand what’s different than what you expect to happen? :)

On Mon, Oct 26 2020 at 19:35, zctya notifications@github.com wrote:

[image: WX20201027-103509] https://user-images.githubusercontent.com/10741844/97250082-22750500-1840-11eb-9f01-efefbee3484f.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/beaugunderson/ip-address/issues/121, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAPCX4BQWT5OSHJOA3UORLSMYWYRANCNFSM4TAGDDKA .

zctya commented 4 years ago

// ip-address: 7.0.1 var Address6 = require('ip-address').Address6; var address6 = new Address6('0:0:0:0:0:0:0:0') address6.isCorrect() // return false except true

beaugunderson commented 4 years ago

that's not what isCorrect is for—"::" is the "correct" representation of that address; I think that function should be renamed to make it more obvious what it does :)

you can use the static Address6.isValid (added in 7.1.0) for checking validity; and if you do instantiate an address (e.g. with new Address6('0:0:0:0:0:0:0:0')) then it will throw an exception if the address is inValid and succeed otherwise (this was a change based on user feedback and made in 7.0.0; previously the returned Address6 had an isValid() method but this was made static).

beaugunderson commented 4 years ago

to further explain; if you visit v6decode.com (which uses this library) and enter an address you can see how the various flags work out, e.g. for 0:0:0:0:0:0:0:0:

image

the definition of "correct" is the one detailed here: https://tools.ietf.org/html/rfc5952#page-10

beaugunderson commented 4 years ago

pre-7.0.0

const a = new Address6('0:0:0:0:0:0:0:0');
a.isValid(); // true

const b = new Address6('invalid address');
b.isValid(); // false

in 7.0.0 and above

const a = new Address6('0:0:0:0:0:0:0:0'); // doesn't throw an exception, so you know the address is valid

const b = new Address6('invalid address'); // throws an exception

// or you can use the new static method
Address6.isValid('0:0:0:0:0:0:0:0'); // true

Address6.isValid('invalid address'); // false
zctya commented 4 years ago

Thanks

zctya commented 4 years ago

in 7.1.0 passed Address6.isValid('0:0:0:0:0:0:0:0'); // true

Address6.isValid('invalid address'); // false