Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Possible portNumbers argument validation bug? #62

Closed
jonahsnider opened this issue Feb 20, 2022 · 3 comments · Fixed by #64
Closed

Possible portNumbers argument validation bug? #62

jonahsnider opened this issue Feb 20, 2022 · 3 comments · Fixed by #64

Comments

@jonahsnider
Copy link
Contributor

get-port/index.js

Lines 163 to 165 in 50e24f6

if (to < minPort || to > maxPort + 1) {
throw new RangeError(`'to' must be between ${minPort} and ${maxPort + 1}`);
}

Is this + 1 logic correct?

If you run this snippet:

import { portNumbers } from 'get-port';

console.log([...portNumbers(65535, 65536)]);

You get the output

[ 65535, 65536 ]

The maximum port number should be 65,535 but the argument validation seems to allow the value 65536 to be returned.

If this is a bug I'd be happy to PR it.

@sindresorhus
Copy link
Owner

@mastrzyz

@mastrzyz
Copy link
Contributor

Interesting, this does look like a bug but , I'd like some more context @sindresorhus , previously the code was :

	if (to < 1024 || to > 65_536) {
		throw new RangeError('`to` must be between 1024 and 65536');
	}

My change d03c07b , changed it to :

       const maxPort = 65_535;
	if (to < minPort || to > maxPort + 1) {
		throw new RangeError(`'to' must be between ${minPort} and ${maxPort + 1}`);
	}

So its effectively the same code as before, was it always a bug here?

@sindresorhus
Copy link
Owner

was it always a bug here?

Seems so.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants