Skip to content

Empty .to([]) sends to everybody instead of nobody #4645

@jyustman

Description

@jyustman

Describe the bug
io.to([]).emit("hello") sends to everybody instead of nobody

To Reproduce

Socket.IO server version: 4.6.1

Server

import { Server } from "socket.io";

const io = new Server(3000, {});

io.on("connection", () => {
  io.to([]).emit("hello");
});

Socket.IO client version: 4.6.1

Client

import { io } from "socket.io-client";

const socket = io("ws://localhost:3000/", {});

socket.on("hello", () => {
  console.log("hello received");
});

Expected behavior
I expect no message to be sent when an empty array is passed to .to().

Platform:

  • OS: macOS 13.2

Additional context
It's easy to work around, but the behavior was unexpected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions