From 9c8bc583e0eb5a01c0b607d96be6ecab5884b4fa Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Wed, 28 Oct 2020 13:03:48 +0000 Subject: [PATCH 1/3] Hide inline images when preference disabled As a first attempt, this drops inline images (as if they were not present at all) when the "show images" preference is disabled. Future work might expose some UI to reveal them like standalone image events have. Fixes https://github.com/vector-im/element-web/issues/15573 --- src/HtmlUtils.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/HtmlUtils.tsx b/src/HtmlUtils.tsx index c503247bf7a..25ff7f49a81 100644 --- a/src/HtmlUtils.tsx +++ b/src/HtmlUtils.tsx @@ -29,6 +29,7 @@ import EMOJIBASE_REGEX from 'emojibase-regex'; import url from 'url'; import {MatrixClientPeg} from './MatrixClientPeg'; +import SettingsStore from './settings/SettingsStore'; import {tryTransformPermalinkToLocalHref} from "./utils/permalinks/Permalinks"; import {SHORTCODE_TO_EMOJI, getEmojiFromUnicode} from "./emoji"; import ReplyThread from "./components/views/elements/ReplyThread"; @@ -171,7 +172,7 @@ const transformTags: IExtendedSanitizeOptions["transformTags"] = { // custom to // Strip out imgs that aren't `mxc` here instead of using allowedSchemesByTag // because transformTags is used _before_ we filter by allowedSchemesByTag and // we don't want to allow images with `https?` `src`s. - if (!attribs.src || !attribs.src.startsWith('mxc://')) { + if (!attribs.src || !attribs.src.startsWith('mxc://') || !SettingsStore.getValue("showImages")) { return { tagName, attribs: {}}; } attribs.src = MatrixClientPeg.get().mxcUrlToHttp( From ac7991c4943fcb4a564ad0631949d3f6158d0a87 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Wed, 28 Oct 2020 13:11:35 +0000 Subject: [PATCH 2/3] Add comment --- src/HtmlUtils.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/HtmlUtils.tsx b/src/HtmlUtils.tsx index 25ff7f49a81..09a511af092 100644 --- a/src/HtmlUtils.tsx +++ b/src/HtmlUtils.tsx @@ -172,6 +172,9 @@ const transformTags: IExtendedSanitizeOptions["transformTags"] = { // custom to // Strip out imgs that aren't `mxc` here instead of using allowedSchemesByTag // because transformTags is used _before_ we filter by allowedSchemesByTag and // we don't want to allow images with `https?` `src`s. + // We also drops inline images (as if they were not present at all) when the "show + // images" preference is disabled. Future work might expose some UI to reveal them + // like standalone image events have. if (!attribs.src || !attribs.src.startsWith('mxc://') || !SettingsStore.getValue("showImages")) { return { tagName, attribs: {}}; } From 5f840da38a818dbfb1f4ab2b2320b8e70a594985 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Wed, 28 Oct 2020 13:12:12 +0000 Subject: [PATCH 3/3] Fix typo --- src/HtmlUtils.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HtmlUtils.tsx b/src/HtmlUtils.tsx index 09a511af092..07bfd4858ae 100644 --- a/src/HtmlUtils.tsx +++ b/src/HtmlUtils.tsx @@ -172,7 +172,7 @@ const transformTags: IExtendedSanitizeOptions["transformTags"] = { // custom to // Strip out imgs that aren't `mxc` here instead of using allowedSchemesByTag // because transformTags is used _before_ we filter by allowedSchemesByTag and // we don't want to allow images with `https?` `src`s. - // We also drops inline images (as if they were not present at all) when the "show + // We also drop inline images (as if they were not present at all) when the "show // images" preference is disabled. Future work might expose some UI to reveal them // like standalone image events have. if (!attribs.src || !attribs.src.startsWith('mxc://') || !SettingsStore.getValue("showImages")) {