diff --git a/src/convert.ts b/src/convert.ts index 3cbb8321..cbc5b078 100644 --- a/src/convert.ts +++ b/src/convert.ts @@ -32,6 +32,7 @@ export function convert (proto: string, a: string | Uint8Array): Uint8Array | st /** * Convert [code,Uint8Array] to string */ +// eslint-disable-next-line complexity export function convertToString (proto: number | string, buf: Uint8Array): string { const protocol = getProtocol(proto) switch (protocol.code) { @@ -40,6 +41,8 @@ export function convertToString (proto: number | string, buf: Uint8Array): strin return bytes2ip(buf) case 42: // ipv6zone return bytes2str(buf) + case 43: // ipcidr + return uint8ArrayToString(buf, 'base10') case 6: // tcp case 273: // udp @@ -71,6 +74,7 @@ export function convertToString (proto: number | string, buf: Uint8Array): strin } } +// eslint-disable-next-line complexity export function convertToBytes (proto: string | number, str: string): Uint8Array { const protocol = getProtocol(proto) switch (protocol.code) { @@ -80,6 +84,8 @@ export function convertToBytes (proto: string | number, str: string): Uint8Array return ip2bytes(str) case 42: // ipv6zone return str2bytes(str) + case 43: // ipcidr + return uint8ArrayFromString(str, 'base10') case 6: // tcp case 273: // udp diff --git a/test/filter/multiaddr-filter.spec.ts b/test/filter/multiaddr-filter.spec.ts index d618889f..81d39435 100644 --- a/test/filter/multiaddr-filter.spec.ts +++ b/test/filter/multiaddr-filter.spec.ts @@ -14,7 +14,9 @@ describe('MultiaddrFilter', () => { ['/ip4/192.168.10.10/ipcidr/24', '/ip4/192.168.11.2/udp/60', false], ['/ip4/192.168.10.10/ipcidr/24', '/ip6/2001:db8:3333:4444:5555:6666:7777:8888/tcp/60', false], ['/ip6/2001:db8:3333:4444:5555:6666:7777:8888/ipcidr/60', '/ip6/2001:0db8:3333:4440:0000:0000:0000:0000/tcp/60', true], - ['/ip6/2001:db8:3333:4444:5555:6666:7777:8888/ipcidr/60', '/ip6/2001:0db8:3333:4450:0000:0000:0000:0000/tcp/60', false] + ['/ip6/2001:db8:3333:4444:5555:6666:7777:8888/ipcidr/60', '/ip6/2001:0db8:3333:4450:0000:0000:0000:0000/tcp/60', false], + ['/ip6/2001:db8:3333:4444:5555:6666:7777:8888/ipcidr/128', '/ip6/2001:db8:3333:4444:5555:6666:7777:8888/tcp/60', true], + ['/ip6/2001:db8:3333:4444:5555:6666:7777:8888/ipcidr/128', '/ip6/2001:db8:3333:4444:5555:6666:7777:8880/tcp/60', false] ] cases.forEach(([cidr, ip, result]) => {