whitequark / ipaddr.js

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

[BUG] IPv6 Shortening is not right #155

Closed avasant21 closed 2 years ago

avasant21 commented 3 years ago

the below toString() operation is wrong.

ipaddr.parse("2001:0000:0000:0db8:0000:0000:0000:0001").toString(); '2001::db8:0:0:0:1' --> This format is not the right one

rfc5952: https://www.rfc-editor.org/rfc/rfc5952.txt

4.2.3. Choice in Placement of "::"

When there is an alternative choice in the placement of a "::", the longest run of consecutive 16-bit 0 fields MUST be shortened (i.e., the sequence with three consecutive zero fields is shortened in 2001:0:0:1:0:0:0:1). When the length of the consecutive 16-bit 0 fields are equal (i.e., 2001:db8:0:0:1:0:0:1), the first sequence of zero bits MUST be shortened. For example, 2001:db8::1:0:0:1 is correct representation.

So in our case, IPv6: 2001:0000:0000:0db8:0000:0000:0000:0001 The right shortened representation should have been: 2001:0:0:db8::1

Kr0san89 commented 1 year ago

@whitequark can you publish this change on npm? thanks

whitequark commented 1 year ago

Done as 2.1.0

Kr0san89 commented 1 year ago

unfortunately on npm it is still 2.0.1 i guess you still need to publish?

whitequark commented 1 year ago

Yeah I forgot. Seems like publishing is broken now:

npm notice
npm notice 📦  ipaddr.js@2.1.0
npm notice === Tarball Contents ===
npm notice 1.1kB  LICENSE
npm notice 34.3kB lib/ipaddr.js
npm notice 11.9kB ipaddr.min.js
npm notice 857B   package.json
npm notice 694B   Changes.md
npm notice 8.5kB  README.md
npm notice 2.9kB  lib/ipaddr.js.d.ts
npm notice === Tarball Details ===
npm notice name:          ipaddr.js
npm notice version:       2.1.0
npm notice package size:  15.2 kB
npm notice unpacked size: 60.2 kB
npm notice shasum:        2119bc447ff8c257753b196fc5f1ce08a4cdf39f
npm notice integrity:     sha512-LlbxQ7xKzfBus[...]xtAVu9T3OelJQ==
npm notice total files:   7
npm notice
npm ERR! code E404
npm ERR! 404 Not Found - PUT https://registry.npmjs.org/ipaddr.js - Not found
npm ERR! 404
npm ERR! 404  'ipaddr.js@2.1.0' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/whitequark/.npm/_logs/2023-05-30T14_35_42_136Z-debug.log
whitequark commented 1 year ago

Oh, it's because they started requiring OTPs and didn't do error messages well. Published now.