beaugunderson / ip-address

💻 a library for parsing and manipulating IPv4 and IPv6 addresses in JavaScript
http://ip-address.js.org/
MIT License
525 stars 71 forks source link

Forward and backward conversion with arpa format for IPv6 don't match #141

Open leftshift opened 3 years ago

leftshift commented 3 years ago

While working on #140 and adding a test that converts the valid ipv4 addresses to reverse arpa format and back and checks whether they match, I also tried adding the same kind of test for IPv6.

That test however failed, because reverseForm will cut some nibbles off based on the netmask. Then, trying to convert back to an address will fail because fromArpa only accepts full-length reverse addresses.

I'm not 100% sure about the reason reverseForm will cut the address shorter in those cases, I haven't found anything about that in the respective RFCs, if you could point me to somewhere where this is used I'd be interested.

Just changing the default behaviour probably isn't possible though, since someone might rely on this behaviour. One possibility I see is adding another option to ReverseFormOptions to set whether the netmask should be considered when generating the reverse form or the full lenth reverse form should always be generated.