From 90b572f07413ebcbc93bc33fc25e4a14f754b963 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 3 Jul 2023 16:56:58 +0100 Subject: [PATCH] Inhibit url previews on MXIDs containing slashes same as those without (#11160) --- src/components/views/messages/TextualBody.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/views/messages/TextualBody.tsx b/src/components/views/messages/TextualBody.tsx index 3c4e98fb58..99ab61b1b6 100644 --- a/src/components/views/messages/TextualBody.tsx +++ b/src/components/views/messages/TextualBody.tsx @@ -388,6 +388,14 @@ export default class TextualBody extends React.Component { return false; } + const url = node.getAttribute("href"); + const host = url?.match(/^https?:\/\/(.*?)(\/|$)/)?.[1]; + + // never preview permalinks (if anything we should give a smart + // preview of the room/user they point to: nobody needs to be reminded + // what the matrix.to site looks like). + if (!host || isPermalinkHost(host)) return false; + // as a random heuristic to avoid highlighting things like "foo.pl" // we require the linked text to either include a / (either from http:// // or from a full foo.bar/baz style schemeless URL) - or be a markdown-style @@ -397,14 +405,6 @@ export default class TextualBody extends React.Component { return true; } - const url = node.getAttribute("href"); - const host = url?.match(/^https?:\/\/(.*?)(\/|$)/)?.[1]; - - // never preview permalinks (if anything we should give a smart - // preview of the room/user they point to: nobody needs to be reminded - // what the matrix.to site looks like). - if (!host || isPermalinkHost(host)) return false; - if (node.textContent?.toLowerCase().trim().startsWith(host.toLowerCase())) { // it's a "foo.pl" style link return false;