-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port from ip to ipaddr.js NPM module #1455
Conversation
`ip` is a node.js module, and was never meant for running in a browser. It magically happened to work until version 1.1.8 despite it doing things like `require('buffer')` (i.e. not an ESM). In version 2.0.1 this broke completely as it tries to `require('os')`. Replace this with https://www.npmjs.com/package/ipaddr.js which has a comparable API and size (the actually bundled library is 12 KB for both modules). Closes cockpit-project#1451
} catch (_ex) { | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 2 added lines are not executed by any test. Details
if (/^[0-9]+$/.test(prefixOrNetmask)) { | ||
try { | ||
return ipaddr.IPv4.subnetMaskFromPrefixLength(parseInt(prefixOrNetmask)).toString(); | ||
} catch (_ex) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This added line is not executed by any test. Details
if (!ip.isV4Format(network) || !validateNetmask(netmask) || !ip.isV4Format(ipaddr)) | ||
export function isIpv4InNetwork(network, netmask, address) { | ||
if (!validateIpv4(network) || !validateIpv4(address)) | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This added line is not executed by any test. Details
try { | ||
ipaddr.IPv6.subnetMaskFromPrefixLength(prefix); | ||
return true; | ||
} catch (_ex) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This added line is not executed by any test. Details
ip = ip.substring(0, prefix); | ||
export function isIpv6InNetwork(network, prefix, address) { | ||
if (!validateIpv6(network) || !validateIpv6Prefix(prefix) || !validateIpv6(address)) | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This added line is not executed by any test. Details
ip
is a node.js module, and was never meant for running in a browser. It magically happened to work until version 1.1.8 despite it doing things likerequire('buffer')
(i.e. not an ESM).In version 2.0.1 this broke completely as it tries to
require('os')
. Replace this with https://www.npmjs.com/package/ipaddr.js which has a comparable API and size (the actually bundled library is 12 KB for both modules).Closes #1451