-
Notifications
You must be signed in to change notification settings - Fork 454
Add port type and range validation to micro. #320
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
Conversation
Great idea, thanks! |
@@ -82,6 +82,15 @@ if (!existsSync(file)) { | |||
process.exit(1) | |||
} | |||
|
|||
const { port, host } = flags | |||
if (isNaN(port) || (!isNaN(port) && (port < 1 || port >= 2 ** 16))) { |
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.
You should prefer Number.isNaN
over isNaN
.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN
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.
The 2 ** 16
statement is causing trouble for me on Node 8.9.1 6.5.0.
if (isNaN(port) || (!isNaN(port) && (port < 1 || port >= 2 ** 16))) {
^
SyntaxError: Unexpected token *
Any reason to use this over Math.pow
or just port > 65535
?
Edit: nvm
was misbehaving and running this under Node 6.5.0, but it works fine under 8.9.1. Feel free to ignore the above :)
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.
shouldn't we specify an engines
field in the package.json so we at least get a npm warning when installing ?
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.
Nothing against Math.pow
, just sugar syntax there. And since micro expects the usage of async/await
i thought something that was available earlier wouldn't hurt.
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.
@rapzo ^ |
On it. Thanks @sindresorhus! |
Assuming that unix sockets are not supported since the message identifies them as
undefined
.I'll gladly patch micro-dev with the same, if the change makes sense.