From 9b2223e38303aa64482ec1e2bee957748383704e Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Mon, 21 Jul 2025 11:30:51 +0100 Subject: [PATCH] Trim roomId when parsing from URL --- src/UrlParams.test.ts | 10 ++++++++++ src/UrlParams.ts | 12 ++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/UrlParams.test.ts b/src/UrlParams.test.ts index b65638e0..14635a91 100644 --- a/src/UrlParams.test.ts +++ b/src/UrlParams.test.ts @@ -82,6 +82,16 @@ describe("UrlParams", () => { getRoomIdentifierFromUrl("", `?roomId=${ROOM_ID}`, "").roomId, ).toBe(ROOM_ID); }); + it("(roomId with unprintable chatacters)", () => { + const invisibleChar = "⁦"; + expect( + getRoomIdentifierFromUrl( + "", + `?roomId=${invisibleChar}${ROOM_ID}${invisibleChar}`, + "", + ).roomId, + ).toBe(ROOM_ID); + }); }); it("ignores room alias", () => { diff --git a/src/UrlParams.ts b/src/UrlParams.ts index 9f89fd47..3b55ed2a 100644 --- a/src/UrlParams.ts +++ b/src/UrlParams.ts @@ -387,10 +387,14 @@ export function getRoomIdentifierFromUrl( // Make sure roomId is valid let roomId: string | null = parser.getParam("roomId"); - if (!roomId?.startsWith("!")) { - roomId = null; - } else if (!roomId.includes("")) { - roomId = null; + if (roomId !== null) { + // Replace any non-printable characters that another client may have inserted. + roomId = roomId.replaceAll(/^[^ -~]+|[^ -~]+$/g, ""); + if (!roomId.startsWith("!")) { + roomId = null; + } else if (!roomId.includes("")) { + roomId = null; + } } return {