whitequark / ipaddr.js

IP address manipulation library in JavaScript
MIT License
576 stars 92 forks source link

Compressed IPv4 don't parse #133

Closed Taiki-San closed 4 years ago

Taiki-San commented 4 years ago

Hi!

We discovered that compressed IPv4 (127.1 instead of 127.0.0.1) are accepted by http libraries despite raising ipaddr: the address has neither IPv6 nor IPv4 format when calling ipaddr.parse on it.

Because I couldn't find mentions of such a format in the formatting spec for IPv4 I could find, I don't know if that's a case you want to support in the library.

Otherwise, I could add a first stage in my code before ipaddr to try to detect and complete them.

Taiki-San commented 4 years ago

Digging a bit, it looks like this is actually a classful variants of the IP that the parser explicitly ignore. Would you be open to a PR adding support?

whitequark commented 4 years ago

Yup, sure. Looks like I missed some--I thought I got them all, but it was a long time ago.

Taiki-San commented 4 years ago

You explicitly mentioned those in a comment (https://github.com/whitequark/ipaddr.js/blob/master/lib/ipaddr.js#L316-L319) so I wasn't sure if not supporting them was a deliberate design decision. Thanks for the precision, working the on the PR right now :)

whitequark commented 4 years ago

It was sort of deliberate. I included all the bizarre formats (like a single hex field) for compatibility with inet_aton. I didn't include the classful ones because, IIRC, I didn't feel like implementing them. Since inet_aton does accept those, and I don't have to do the work, there's no reason to not accept a PR.