Skip to content

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

Merged
merged 1 commit into from
Nov 2, 2017
Merged

Conversation

rapzo
Copy link
Contributor

@rapzo rapzo commented Nov 2, 2017

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.

@leo
Copy link
Contributor

leo commented Nov 2, 2017

Great idea, thanks!

@leo leo merged commit d03895e into vercel:master Nov 2, 2017
@@ -82,6 +82,15 @@ if (!existsSync(file)) {
process.exit(1)
}

const { port, host } = flags
if (isNaN(port) || (!isNaN(port) && (port < 1 || port >= 2 ** 16))) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@frolic frolic Nov 11, 2017

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 :)

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 ?

Copy link
Contributor Author

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.

https://github.com/zeit/micro/blob/2408dd57a2c2e4072563d7be0967652deeddb0bd/lib/handler.js#L23

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for some reason the error message was not displayed in my case with node v 6.2.3

upgraded to 8.7 and 👌

capture d ecran 2017-11-14 a 00 54 03

@leo
Copy link
Contributor

leo commented Nov 3, 2017

@rapzo ^

@rapzo
Copy link
Contributor Author

rapzo commented Nov 3, 2017

On it. Thanks @sindresorhus!

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.

5 participants