Merge pull request #1781 from thecodingmachine/fix_link_encoding_in_chat

Fix the way links are encoded in chat
This commit is contained in:
David Négrier 2022-01-27 23:00:37 +01:00 committed by GitHub
commit 4aee41f9fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,6 +40,7 @@ export class HtmlUtils {
const urlRegex = /(https?:\/\/[^\s]+)/g;
text = HtmlUtils.escapeHtml(text);
return text.replace(urlRegex, (url: string) => {
url = HtmlUtils.htmlDecode(url);
const link = document.createElement("a");
link.href = url;
link.target = "_blank";
@ -50,6 +51,15 @@ export class HtmlUtils {
});
}
private static htmlDecode(input: string): string {
const doc = new DOMParser().parseFromString(input, "text/html");
const text = doc.documentElement.textContent;
if (text === null) {
throw new Error("Unexpected non parseable string");
}
return text;
}
public static isClickedInside(event: MouseEvent, target: HTMLElement): boolean {
return !!event.composedPath().find((et) => et === target);
}