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

lib: allow server.listen({ port: "1234" }) #1116

Merged
merged 1 commit into from
Mar 10, 2015

Conversation

bnoordhuis
Copy link
Member

net.connect() accepts { port: "1234" } (i.e. a string) as of commit
9d2b89d ("net: allow port 0 in connect()") but net.Server#listen()
did not, creating a minor inconsistency. This commit rectifies that.

Fixes: #1111

R=@cjihrig

https://jenkins-iojs.nodesource.com/view/iojs/job/iojs+any-pr+multi/270/

// is an integer and that it falls within the legal range of port numbers.
function isLegalPort(port) {
if (typeof port === 'string' && port.trim() === '')
return false;
Copy link
Member Author

Choose a reason for hiding this comment

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

@cjihrig What was the motivation for disallowing an empty string?

Copy link
Contributor

Choose a reason for hiding this comment

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

Empty string and strings of 1 or more spaces become 0 when the + operator is applied. Since we want to allow zero, I had to specifically check for that case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, that much I get. It's not really clear to me though why undefined is allowed (and interpreted as 0) but not a blank string.

Copy link
Contributor

Choose a reason for hiding this comment

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

@misterdjules and I had a fair amount of discussion about this. undefined is allowed because the argument is optional and needs a default value. The empty string means you are explicitly passing in an "incorrect" value. I actually wasn't the one to add the original checks. However, I moved the validation, so I sort of took ownership of it when the bug (port zero was no longer allowed) was reported against 0.12.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, thanks for the explanation. It feels kind of quirky but I don't have a strong enough opinion to file a PR for it. :-)

@cjihrig
Copy link
Contributor

cjihrig commented Mar 10, 2015

LGTM. The CI appears to be happyish

net.connect() accepts `{ port: "1234" }` (i.e. a string) as of commit
9d2b89d ("net: allow port 0 in connect()") but net.Server#listen()
did not, creating a minor inconsistency.  This commit rectifies that.

Fixes: nodejs#1111
PR-URL: nodejs#1116
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
@bnoordhuis bnoordhuis closed this Mar 10, 2015
@bnoordhuis bnoordhuis deleted the issue1111 branch March 10, 2015 15:14
@bnoordhuis bnoordhuis merged commit 480b482 into nodejs:v1.x Mar 10, 2015
@rvagg
Copy link
Member

rvagg commented Mar 10, 2015

This is semver-minor right? Perhaps we should let these PRs simmer a little longer before landing.

@bnoordhuis
Copy link
Member Author

I guess it is but I already landed it. Want me to revert it for now?

@rvagg
Copy link
Member

rvagg commented Mar 10, 2015

No, just making a point that when changes are non-trivial we should probably be allowing time for dissent and discussion. I'm guessing this one is not too controversial.

@Fishrock123 Fishrock123 added the semver-minor PRs that contain new features and should be released in the next minor version. label Mar 14, 2015
@rvagg
Copy link
Member

rvagg commented Mar 14, 2015

I'd like to do a release but this would justify a 1.6.0 which is kind of unfortunate because that's a pathetic minor version bump so I'd like to wait a few days to see if we can get something out of one of the other semver-minor PRs in flux atm.

We could also have a debate about whether this really is semver-minor..

@rvagg rvagg mentioned this pull request Mar 14, 2015
@cjihrig
Copy link
Contributor

cjihrig commented Mar 15, 2015

One could argue that listen() and connect() should accept the same port values, which would make this just a bug fix :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants