Trim roomId when parsing from URL

This commit is contained in:
Half-Shot
2025-07-21 11:30:51 +01:00
parent 01ede7629e
commit 9b2223e383
2 changed files with 18 additions and 4 deletions

View File

@@ -82,6 +82,16 @@ describe("UrlParams", () => {
getRoomIdentifierFromUrl("", `?roomId=${ROOM_ID}`, "").roomId, getRoomIdentifierFromUrl("", `?roomId=${ROOM_ID}`, "").roomId,
).toBe(ROOM_ID); ).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", () => { it("ignores room alias", () => {

View File

@@ -387,10 +387,14 @@ export function getRoomIdentifierFromUrl(
// Make sure roomId is valid // Make sure roomId is valid
let roomId: string | null = parser.getParam("roomId"); let roomId: string | null = parser.getParam("roomId");
if (!roomId?.startsWith("!")) { if (roomId !== null) {
roomId = null; // Replace any non-printable characters that another client may have inserted.
} else if (!roomId.includes("")) { roomId = roomId.replaceAll(/^[^ -~]+|[^ -~]+$/g, "");
roomId = null; if (!roomId.startsWith("!")) {
roomId = null;
} else if (!roomId.includes("")) {
roomId = null;
}
} }
return { return {