From 23971b3d0d5fb3627d68588f9776e32aaadedb59 Mon Sep 17 00:00:00 2001 From: Bastian Date: Thu, 31 Jan 2019 22:35:58 +0100 Subject: [PATCH] Refactor to use HtmlUtils for linkifying and sanitizing Signed-off-by: Bastian --- src/SlashCommands.js | 9 ++------- src/components/structures/RoomDirectory.js | 9 ++------- src/components/views/messages/TextualBody.js | 7 +------ src/components/views/rooms/LinkPreviewWidget.js | 12 ++++-------- src/components/views/rooms/RoomDetailRow.js | 8 ++------ src/components/views/rooms/RoomHeader.js | 8 ++------ 6 files changed, 13 insertions(+), 40 deletions(-) diff --git a/src/SlashCommands.js b/src/SlashCommands.js index f31bf32eac..be1f4ebda8 100644 --- a/src/SlashCommands.js +++ b/src/SlashCommands.js @@ -27,12 +27,7 @@ import SettingsStore, {SettingLevel} from './settings/SettingsStore'; import {MATRIXTO_URL_PATTERN} from "./linkify-matrix"; import * as querystring from "querystring"; import MultiInviter from './utils/MultiInviter'; -import * as linkify from 'linkifyjs'; -import linkifyString from 'linkifyjs/string'; -import linkifyMatrix from './linkify-matrix'; -import sanitizeHtml from 'sanitize-html'; - -linkifyMatrix(linkify); +import { linkifyAndSanitizeHtml } from './HtmlUtils'; class Command { constructor({name, args='', description, runFn, hideCompletionAfterSpace=false}) { @@ -154,7 +149,7 @@ export const CommandMap = { const topicEvents = room.currentState.getStateEvents('m.room.topic', ''); const topic = topicEvents.getContent().topic; - const topicHtml = topic ? linkifyString(sanitizeHtml(topic)) : _t('This room has no topic.'); + const topicHtml = topic ? linkifyAndSanitizeHtml(topic) : _t('This room has no topic.'); const InfoDialog = sdk.getComponent('dialogs.InfoDialog'); Modal.createTrackedDialog('Slash Commands', 'Topic', InfoDialog, { diff --git a/src/components/structures/RoomDirectory.js b/src/components/structures/RoomDirectory.js index c18dd4d48a..08d3403bc3 100644 --- a/src/components/structures/RoomDirectory.js +++ b/src/components/structures/RoomDirectory.js @@ -24,10 +24,7 @@ const Modal = require('../../Modal'); const sdk = require('../../index'); const dis = require('../../dispatcher'); -const linkify = require('linkifyjs'); -const linkifyString = require('linkifyjs/string'); -const linkifyMatrix = require('../../linkify-matrix'); -const sanitizeHtml = require('sanitize-html'); +import { linkifyAndSanitizeHtml } from '../../HtmlUtils'; import Promise from 'bluebird'; import { _t } from '../../languageHandler'; @@ -37,8 +34,6 @@ import {instanceForInstanceId, protocolNameForInstanceId} from '../../utils/Dire const MAX_NAME_LENGTH = 80; const MAX_TOPIC_LENGTH = 160; -linkifyMatrix(linkify); - module.exports = React.createClass({ displayName: 'RoomDirectory', @@ -438,7 +433,7 @@ module.exports = React.createClass({ if (topic.length > MAX_TOPIC_LENGTH) { topic = `${topic.substring(0, MAX_TOPIC_LENGTH)}...`; } - topic = linkifyString(sanitizeHtml(topic)); + topic = linkifyAndSanitizeHtml(topic); rows.push(