partysocket: a room name with ? or # is not encoded in the URL

オープン 初心者向け
#443 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
nodejs, typescript
領域
networking

調査の方向性

URLは packages/partysocket/src/index.ts の107行目付近にある getPartyInfo() で組み立てられており、パーティ名とルーム名がエンコードされずに挿入されています。まずそこから始め、次にissueの再現スクリプトを、それが起動するサーバーに対して実行し、? と # の動作を確認してください。ルーム a?b がクエリ文字列を保ったまま /parties/main/a%3Fb としてサーバーに届き、ルーム a#b に接続できれば完了です。partysocketのテストスイートに回帰テストも追加してください。

索引モデルが issue の本文から書いたものです。

説明

getPartyInfo() puts the party and room names into the URL as they are. A ? in a name starts the query string, so the server gets another room name and the rest of the name as a query. A # starts a fragment, and the WebSocket constructor rejects a URL with a fragment, so the socket never connects.

https://github.com/cloudflare/partykit/blob/partysocket%401.3.0/packages/partysocket/src/index.ts#L107

Repro

The packages: [email protected], [email protected]. Install them with npm i [email protected] [email protected].

// npm install, then: node repro.ts (Node.js 22.18 or later runs TypeScript directly)
import type { AddressInfo } from "node:net";
import PartySocket from "partysocket";
import { WebSocketServer } from "ws";

const wss = new WebSocketServer({ host: "127.0.0.1", port: 0 });
await new Promise((resolve) => wss.once("listening", resolve));
wss.on("connection", (_client, req) => {
  console.log("the server got the URL:", req.url);
});
const host = `127.0.0.1:${(wss.address() as AddressInfo).port}`;

// room "a?b"
const a = new PartySocket({ host, room: "a?b", id: "client-1" });
await new Promise((resolve) => setTimeout(resolve, 300));
a.close();

// room "a#b"
const b = new PartySocket({ host, room: "a#b", minReconnectionDelay: 50, maxReconnectionDelay: 50 });
let errors = 0;
let firstError: string | undefined;
b.addEventListener("error", (e) => {
  errors++;
  firstError ??= e.message;
});
await new Promise((resolve) => setTimeout(resolve, 500));
console.log(`room "a#b": ${errors} error events in 500 ms, the first: ${firstError}`);
b.close();
for (const client of wss.clients) client.terminate();
wss.close();

node repro.ts (Node.js 22.18 or later runs TypeScript directly)

Actual

the server got the URL: /parties/main/a?b?_pk=client-1
room "a#b": 10 error events in 500 ms, the first: hash

Expected

The room name stays in the path of the URL, for example /parties/main/a%3Fb?_pk=client-1, and a room name with # connects.

A fix

A fix with a new test is on the branch fix/partysocket-encode-room-name of my fork, at 720a46c. On a GitHub Actions runner, the new test fails before the change and passes after it, and the whole partysocket suite passes. This repository accepts pull requests only from collaborators, so I did not open a pull request. I can open one if you allow it, or you can take the commit.

I found this with AI assistance (Claude) during a review of WebSocket client libraries. The repro above was run with partysocket 1.3.0 on Node.js 24.22.2 on Linux (a GitHub Actions runner), and the output above is from that run. The fix was also prepared with AI assistance (Claude).

主要言語
TypeScript
スター
1.3k
フォーク
86
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

cloudflare/partykit のほかの issue

cloudflare/partykit の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。