Skip to content

Commit 26328d2

Browse files
authored
Keep the port in place when listen() gets an empty host (#1319)
The port loop started at index min(1, host.length()), so an empty host string was read as the port: listen("", 9001, cb) ended up on a random port with 9001 passed as options. Start after the host slot whenever a host argument was given, whatever its length.
1 parent 9a70747 commit 26328d2

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎src/AppWrapper.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,19 +551,21 @@ void uWS_App_listen(const FunctionCallbackInfo<Value> &args) {
551551
Local<Function>::Cast(args[args.Length() - 1])->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 1, argv).IsEmpty();
552552
};
553553

554-
/* Host is first, if present */
554+
/* Host is first, if present (an empty host still takes that slot) */
555555
std::string host;
556+
int firstNumber = 0;
556557
if (!args[0]->IsNumber()) {
557558
NativeString h(isolate, args[0]);
558559
if (h.isInvalid(args)) {
559560
return;
560561
}
561562
host = h.getString();
563+
firstNumber = 1;
562564
}
563565

564566
/* Port, options are in the middle, if present */
565567
std::vector<int> numbers;
566-
for (int i = std::min<int>(1, host.length()); i < args.Length() - 1; i++) {
568+
for (int i = firstNumber; i < args.Length() - 1; i++) {
567569
numbers.push_back(args[i]->Uint32Value(args.GetIsolate()->GetCurrentContext()).ToChecked());
568570
}
569571

0 commit comments

Comments
 (0)