Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/js/node/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3237,10 +3237,6 @@ Server.prototype.getConnections = function getConnections(callback) {

Server.prototype.listen = function listen(port, hostname, onListen) {
const argsLength = arguments.length;
if (typeof port === "string") {
const numPort = Number(port);
if (!Number.isNaN(numPort)) port = numPort;
}
let backlog;
let path;
let exclusive = false;
Expand All @@ -3249,8 +3245,10 @@ Server.prototype.listen = function listen(port, hostname, onListen) {
let readableAll = false;
let writableAll = false;
let fd;
//port is actually path
if (typeof port === "string") {
// Match Node's normalizeArgs: a positional string argument is a pipe path
// only when isPipeName() is true; otherwise (including "" and " ") it is
// treated as a port and flows to validatePort which rejects empty strings.
if (isPipeName(port)) {
Comment thread
robobun marked this conversation as resolved.
Comment thread
robobun marked this conversation as resolved.
if (Number.isSafeInteger(hostname)) {
if (hostname > 0) {
//hostname is backlog
Expand Down
1 change: 1 addition & 0 deletions src/jsc/bindings/NodeValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ JSC_DEFINE_HOST_FUNCTION(jsFunction_validatePort, (JSC::JSGlobalObject * globalO
if (c >= 0x2029 && c <= 0x2029) return true;
if (c >= 0x202F && c <= 0x202F) return true;
if (c >= 0x205F && c <= 0x205F) return true;
if (c >= 0x3000 && c <= 0x3000) return true;

// LineTerminator ::
if (c == 0x000A) return true; // <LF>
Expand Down
23 changes: 23 additions & 0 deletions test/js/node/net/node-net-server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,29 @@ describe("net.createServer events", () => {
);
});

it.each(["", " ", " ", "\t", "\u3000"])(
"should throw ERR_SOCKET_BAD_PORT synchronously for listen(%j) instead of binding an ephemeral TCP port",
port => {
const server = createServer();
try {
let err: any;
try {
server.listen(port, () => {});
} catch (e) {
err = e;
}
expect(err).toBeDefined();
expect({ code: err.code, message: err.message }).toEqual({
code: "ERR_SOCKET_BAD_PORT",
message: expect.stringContaining("options.port"),
});
expect(server.listening).toBe(false);
} finally {
if (server.listening) server.close();
}
},
);
Comment thread
coderabbitai[bot] marked this conversation as resolved.

it("should call abort with signal", done => {
const { mustCall, mustNotCall } = createCallCheckCtx(done);

Expand Down
Loading