From d1c549335b9d8358dd07166f527c599f8214b397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 27 Jan 2022 19:02:54 +0100 Subject: [PATCH] Fix the way links are encoded in chat Closes #1776 --- front/src/WebRtc/HtmlUtils.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/front/src/WebRtc/HtmlUtils.ts b/front/src/WebRtc/HtmlUtils.ts index c266d558..1c6b8817 100644 --- a/front/src/WebRtc/HtmlUtils.ts +++ b/front/src/WebRtc/HtmlUtils.ts @@ -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); }