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

Open
#4,645 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale

Research direction

Start with the server example using io.to([]).emit("hello") and trace the broadcast path for an empty target list. Confirm the behavior with connected clients, then verify that an empty array sends to no clients and that the behavior is covered by a regression test.

Written by the indexing model from the issue text.

Description

enhancement

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.

Dominant language
TypeScript
Stars
63.2k
Forks
10.3k
Avg merge
11d 20h
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from socketio/socket.io

All issues in socketio/socket.io

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.