Skip to content
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

Merged
merged 1 commit into from
Feb 22, 2024
Merged

Conversation

martinpitt
Copy link
Member

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 #1451

`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
Comment on lines +76 to +77
} catch (_ex) {
return null;
Copy link
Contributor

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) {
Copy link
Contributor

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;
Copy link
Contributor

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) {}
Copy link
Contributor

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;
Copy link
Contributor

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

@martinpitt martinpitt requested a review from jelly February 22, 2024 11:45
src/components/networks/utils.js Show resolved Hide resolved
src/components/networks/utils.js Show resolved Hide resolved
@jelly jelly merged commit f27fc31 into cockpit-project:main Feb 22, 2024
29 checks passed
@martinpitt martinpitt deleted the ipaddr branch February 22, 2024 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants