From 9a46fc18a664d046f45c456b5c6341f3976fe411 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 22 Mar 2022 11:31:59 +0000 Subject: [PATCH 1/2] Fix issue with falsey hrefs being sent in events --- src/HtmlUtils.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/HtmlUtils.tsx b/src/HtmlUtils.tsx index 2f574351c94..5a2318db176 100644 --- a/src/HtmlUtils.tsx +++ b/src/HtmlUtils.tsx @@ -182,7 +182,11 @@ const transformTags: IExtendedSanitizeOptions["transformTags"] = { // custom to ) { delete attribs.target; } + } else { + // Delete the href attrib if it is falsey + delete attribs.href; } + attribs.rel = 'noreferrer noopener'; // https://mathiasbynens.github.io/rel-noopener/ return { tagName, attribs }; }, From b6b0bf4344643ce1ea7d6a25d9b667131b4f9d20 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 22 Mar 2022 11:32:11 +0000 Subject: [PATCH 2/2] Tidy linkify-matrix --- src/linkify-matrix.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/linkify-matrix.ts b/src/linkify-matrix.ts index 1fdd8106ba1..dc0cef48e89 100644 --- a/src/linkify-matrix.ts +++ b/src/linkify-matrix.ts @@ -155,21 +155,21 @@ export const options = { // intercept local permalinks to users and show them like userids (in userinfo of current room) try { const permalink = parsePermalink(href); - if (permalink && permalink.userId) { + if (permalink?.userId) { return { // @ts-ignore see https://linkify.js.org/docs/options.html - click: function(e) { + click: function(e: MouseEvent) { onUserClick(e, permalink.userId); }, }; } else { - // for events, rooms etc. (anything other then users) + // for events, rooms etc. (anything other than users) const localHref = tryTransformPermalinkToLocalHref(href); if (localHref !== href) { // it could be converted to a localHref -> therefore handle locally return { // @ts-ignore see https://linkify.js.org/docs/options.html - click: function(e) { + click: function(e: MouseEvent) { e.preventDefault(); window.location.hash = localHref; }, @@ -184,7 +184,7 @@ export const options = { case Type.UserId: return { // @ts-ignore see https://linkify.js.org/docs/options.html - click: function(e) { + click: function(e: MouseEvent) { const userId = parsePermalink(href).userId; onUserClick(e, userId); }, @@ -192,7 +192,7 @@ export const options = { case Type.RoomAlias: return { // @ts-ignore see https://linkify.js.org/docs/options.html - click: function(e) { + click: function(e: MouseEvent) { const alias = parsePermalink(href).roomIdOrAlias; onAliasClick(e, alias); }, @@ -200,7 +200,7 @@ export const options = { case Type.GroupId: return { // @ts-ignore see https://linkify.js.org/docs/options.html - click: function(e) { + click: function(e: MouseEvent) { const groupId = parsePermalink(href).groupId; onGroupClick(e, groupId); },