diff --git a/src/net-util/export/InterfaceAddress.js b/src/net-util/export/InterfaceAddress.js index f4e7c3d7c..59024172a 100644 --- a/src/net-util/export/InterfaceAddress.js +++ b/src/net-util/export/InterfaceAddress.js @@ -87,10 +87,6 @@ export class InterfaceAddress extends IntfDeconstructable { let needCanonicalization; if (typeof fullAddress === 'string') { fullAddress = InterfaceAddress.parseInterface(fullAddress); - // `parseInterface()` expects `port` not `portNumber`. TODO: Fix it to be - // consistent with this class (not the other way around). - fullAddress.portNumber = fullAddress.port; - delete fullAddress.port; needCanonicalization = false; } else { needCanonicalization = true; @@ -395,13 +391,14 @@ export class InterfaceAddress extends IntfDeconstructable { * port, users of this system might want to provide it more directly. * * @param {string} iface Interface spec to parse. - * @returns {{address: ?string, fd: ?number, port: ?number}} The parsed form. + * @returns {{address: ?string, fd: ?number, portNumber: ?number}} The parsed + * form. */ static parseInterface(iface) { MustBe.string(iface); - const portStr = iface.match(/:(?[0-9]{1,5})$/)?.groups.port ?? null; - const port = portStr ? this.#mustBePortNumber(portStr, true) : null; + const portStr = iface.match(/:(?[0-9]{1,5})$/)?.groups.port ?? null; + const portNumber = portStr ? this.#mustBePortNumber(portStr, true) : null; const addressStr = portStr ? iface.match(/^(?
.*):[^:]+$/).groups.address @@ -417,7 +414,7 @@ export class InterfaceAddress extends IntfDeconstructable { if (addressOrFd.fd) { const fd = MustBe.number(parseInt(addressOrFd.fd), { safeInteger: true, minInclusive: 0, maxInclusive: 65535 }); - return (port === null) ? { fd } : { fd, port }; + return (portNumber === null) ? { fd } : { fd, portNumber }; } const address = InterfaceAddress.canonicalizeAddress(addressOrFd.address); @@ -426,12 +423,12 @@ export class InterfaceAddress extends IntfDeconstructable { // If we managed to parse and made it here, then we are necessarily // looking at an IPv6 address without brackets. throw new Error(`Invalid network interface (missing brackets): ${iface}`); - } else if (port === null) { + } else if (portNumber === null) { // Must specify port at this point. (It's optional with the FD form). throw new Error(`Invalid network interface (missing port): ${iface}`); } - return { address, port }; + return { address, portNumber }; } /** diff --git a/src/net-util/tests/InterfaceAddress.test.js b/src/net-util/tests/InterfaceAddress.test.js index c16e9304b..1ef6d6672 100644 --- a/src/net-util/tests/InterfaceAddress.test.js +++ b/src/net-util/tests/InterfaceAddress.test.js @@ -558,17 +558,17 @@ describe('parseInterface()', () => { test('parses an interface with IPv4 address as expected', () => { const got = InterfaceAddress.parseInterface('12.34.56.78:123'); - expect(got).toStrictEqual({ address: '12.34.56.78', port: 123 }); + expect(got).toStrictEqual({ address: '12.34.56.78', portNumber: 123 }); }); test('parses an interface with IPv6 address as expected', () => { const got = InterfaceAddress.parseInterface('[abc::123:4567]:999'); - expect(got).toStrictEqual({ address: 'abc::123:4567', port: 999 }); + expect(got).toStrictEqual({ address: 'abc::123:4567', portNumber: 999 }); }); test('parses an interface with wildcard address as expected', () => { const got = InterfaceAddress.parseInterface('*:17777'); - expect(got).toStrictEqual({ address: '*', port: 17777 }); + expect(got).toStrictEqual({ address: '*', portNumber: 17777 }); }); test('parses an FD interface with no port as expected', () => { @@ -578,7 +578,7 @@ describe('parseInterface()', () => { test('parses an FD interface with port as expected', () => { const got = InterfaceAddress.parseInterface('/dev/fd/109:914'); - expect(got).toStrictEqual({ fd: 109, port: 914 }); + expect(got).toStrictEqual({ fd: 109, portNumber: 914 }); }); test('accepts the minimum and maximum allowed FD numbers', () => {