Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Fix issue with falsey hrefs being sent in events (#8113)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy committed Mar 23, 2022
1 parent 81df4c0 commit eb66853
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/HtmlUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
},
Expand Down
14 changes: 7 additions & 7 deletions src/linkify-matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,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;
},
Expand All @@ -185,15 +185,15 @@ 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);
},
};
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);
},
Expand All @@ -202,7 +202,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);
},
Expand Down

0 comments on commit eb66853

Please sign in to comment.