Trim extra characters from roomId parameter in URL (#3412)
* Trim roomId when parsing from URL * fix char * fixup * limit to roomId * Add a comment
This commit is contained in:
@@ -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 characters)", () => {
|
||||||
|
const invisibleChar = "\u2066";
|
||||||
|
expect(
|
||||||
|
getRoomIdentifierFromUrl(
|
||||||
|
"",
|
||||||
|
`?roomId=${invisibleChar}${ROOM_ID}${invisibleChar}`,
|
||||||
|
"",
|
||||||
|
).roomId,
|
||||||
|
).toBe(ROOM_ID);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("ignores room alias", () => {
|
it("ignores room alias", () => {
|
||||||
|
|||||||
@@ -398,10 +398,16 @@ 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("")) {
|
// For instance on iOS, some copied links end up with zero width characters on the end which get encoded into the URL.
|
||||||
roomId = null;
|
// This isn't valid for a roomId, so we can freely strip the content.
|
||||||
|
roomId = roomId.replaceAll(/^[^ -~]+|[^ -~]+$/g, "");
|
||||||
|
if (!roomId.startsWith("!")) {
|
||||||
|
roomId = null;
|
||||||
|
} else if (!roomId.includes("")) {
|
||||||
|
roomId = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user