Fix permalink via parsing for rooms

This adjusts the app local link parsing path to better handle `via`s in query
params. Previously this path only expected them when an event ID was also
present, but it's also valid to have `via`s without event IDs as well.

Fixes https://github.com/vector-im/element-web/issues/16345
This commit is contained in:
J. Ryan Stinnett 2021-02-03 15:18:19 +00:00
parent fd7c50f683
commit 474c029db5
3 changed files with 41 additions and 10 deletions

View file

@ -242,6 +242,38 @@ describe("<TextualBody />", () => {
'rel="noreferrer noopener">event link</a> with text</span>',
);
});
it("pills appear for room links with vias", () => {
const ev = mkEvent({
type: "m.room.message",
room: "room_id",
user: "sender",
content: {
body:
"A [room link](https://matrix.to/#/!ZxbRYPQXDXKGmDnJNg:example.com" +
"?via=example.com&via=bob.com) with vias",
msgtype: "m.text",
format: "org.matrix.custom.html",
formatted_body:
"A <a href=\"https://matrix.to/#/!ZxbRYPQXDXKGmDnJNg:example.com" +
"?via=example.com&amp;via=bob.com\">room link</a> with vias",
},
event: true,
});
const wrapper = mount(<TextualBody mxEvent={ev} />);
expect(wrapper.text()).toBe("A !ZxbRYPQXDXKGmDnJNg:example.com with vias");
const content = wrapper.find(".mx_EventTile_body");
expect(content.html()).toBe(
'<span class="mx_EventTile_body markdown-body" dir="auto">' +
'A <span><a class="mx_Pill mx_RoomPill" href="#/room/!ZxbRYPQXDXKGmDnJNg:example.com' +
'?via=example.com&amp;via=bob.com" ' +
'title="!ZxbRYPQXDXKGmDnJNg:example.com"><img class="mx_BaseAvatar mx_BaseAvatar_image" ' +
'src="mxc://avatar.url/room.png" ' +
'style="width: 16px; height: 16px;" alt="" aria-hidden="true">' +
'!ZxbRYPQXDXKGmDnJNg:example.com</a></span> with vias</span>',
);
});
});
it("renders url previews correctly", () => {