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

Commit eb66853

Browse files
authored
Fix issue with falsey hrefs being sent in events (#8113)
1 parent 81df4c0 commit eb66853

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/HtmlUtils.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ const transformTags: IExtendedSanitizeOptions["transformTags"] = { // custom to
182182
) {
183183
delete attribs.target;
184184
}
185+
} else {
186+
// Delete the href attrib if it is falsey
187+
delete attribs.href;
185188
}
189+
186190
attribs.rel = 'noreferrer noopener'; // https://mathiasbynens.github.io/rel-noopener/
187191
return { tagName, attribs };
188192
},

src/linkify-matrix.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,21 +156,21 @@ export const options = {
156156
// intercept local permalinks to users and show them like userids (in userinfo of current room)
157157
try {
158158
const permalink = parsePermalink(href);
159-
if (permalink && permalink.userId) {
159+
if (permalink?.userId) {
160160
return {
161161
// @ts-ignore see https://linkify.js.org/docs/options.html
162-
click: function(e) {
162+
click: function(e: MouseEvent) {
163163
onUserClick(e, permalink.userId);
164164
},
165165
};
166166
} else {
167-
// for events, rooms etc. (anything other then users)
167+
// for events, rooms etc. (anything other than users)
168168
const localHref = tryTransformPermalinkToLocalHref(href);
169169
if (localHref !== href) {
170170
// it could be converted to a localHref -> therefore handle locally
171171
return {
172172
// @ts-ignore see https://linkify.js.org/docs/options.html
173-
click: function(e) {
173+
click: function(e: MouseEvent) {
174174
e.preventDefault();
175175
window.location.hash = localHref;
176176
},
@@ -185,15 +185,15 @@ export const options = {
185185
case Type.UserId:
186186
return {
187187
// @ts-ignore see https://linkify.js.org/docs/options.html
188-
click: function(e) {
188+
click: function(e: MouseEvent) {
189189
const userId = parsePermalink(href).userId;
190190
onUserClick(e, userId);
191191
},
192192
};
193193
case Type.RoomAlias:
194194
return {
195195
// @ts-ignore see https://linkify.js.org/docs/options.html
196-
click: function(e) {
196+
click: function(e: MouseEvent) {
197197
const alias = parsePermalink(href).roomIdOrAlias;
198198
onAliasClick(e, alias);
199199
},
@@ -202,7 +202,7 @@ export const options = {
202202
case Type.GroupId:
203203
return {
204204
// @ts-ignore see https://linkify.js.org/docs/options.html
205-
click: function(e) {
205+
click: function(e: MouseEvent) {
206206
const groupId = parsePermalink(href).groupId;
207207
onGroupClick(e, groupId);
208208
},

0 commit comments

Comments
 (0)