whitequark / ipaddr.js

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

IPv6 toString change in 2.1.0 #168

Closed silverwind closed 8 months ago

silverwind commented 1 year ago

2.0.1

> (await import("ipaddr.js")).default.parse("2000:8000::8:88:8888:8888:8888").toString()
'2000:8000::8:88:8888:8888:8888'

2.1.0

> (await import("ipaddr.js")).default.parse("2000:8000::8:88:8888:8888:8888").toString()
'2000:8000:0:8:88:8888:8888:8888'

is it intentional? I've been using parse+toString to "normalize" an IPv6 (removing extra zeroes), but this change breaks it.

whitequark commented 1 year ago

Probably not. I don't really validate the changes for correctness any more as I haven't had any use for this package in a decade. Ask the people who sent the PRs that went into 2.1.0 directly.

silverwind commented 1 year ago

Yeah I don't care about it either, will switch to my own module for such normalization.

Johann150 commented 8 months ago

I don't think this is a bug because the RFC says not to shorten a single field:

4.2.2 Handling One 16-Bit 0 Field

The symbol "::" MUST NOT be used to shorten just one 16-bit 0 field. For example, the representation 2001:db8:0:1:1:1:1:1 is correct, but 2001:db8::1:1:1:1:1 is not correct.

-- https://datatracker.ietf.org/doc/html/rfc5952#section-4.2.2

silverwind commented 8 months ago

Thanks, so this case of single 0 not being shortened is then working as intended.

BTW, the RFC is self-contradicting with its 'The use of the symbol "::" MUST be used to its maximum capability' statement, there is this open errata.