mirror of https://github.com/vector-im/riot-web
Refactor to use HtmlUtils for linkifying and sanitizing
Signed-off-by: Bastian <matrix@noxware.de>pull/21833/head
parent
9cd13a8893
commit
23971b3d0d
|
@ -27,12 +27,7 @@ import SettingsStore, {SettingLevel} from './settings/SettingsStore';
|
||||||
import {MATRIXTO_URL_PATTERN} from "./linkify-matrix";
|
import {MATRIXTO_URL_PATTERN} from "./linkify-matrix";
|
||||||
import * as querystring from "querystring";
|
import * as querystring from "querystring";
|
||||||
import MultiInviter from './utils/MultiInviter';
|
import MultiInviter from './utils/MultiInviter';
|
||||||
import * as linkify from 'linkifyjs';
|
import { linkifyAndSanitizeHtml } from './HtmlUtils';
|
||||||
import linkifyString from 'linkifyjs/string';
|
|
||||||
import linkifyMatrix from './linkify-matrix';
|
|
||||||
import sanitizeHtml from 'sanitize-html';
|
|
||||||
|
|
||||||
linkifyMatrix(linkify);
|
|
||||||
|
|
||||||
class Command {
|
class Command {
|
||||||
constructor({name, args='', description, runFn, hideCompletionAfterSpace=false}) {
|
constructor({name, args='', description, runFn, hideCompletionAfterSpace=false}) {
|
||||||
|
@ -154,7 +149,7 @@ export const CommandMap = {
|
||||||
|
|
||||||
const topicEvents = room.currentState.getStateEvents('m.room.topic', '');
|
const topicEvents = room.currentState.getStateEvents('m.room.topic', '');
|
||||||
const topic = topicEvents.getContent().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');
|
const InfoDialog = sdk.getComponent('dialogs.InfoDialog');
|
||||||
Modal.createTrackedDialog('Slash Commands', 'Topic', InfoDialog, {
|
Modal.createTrackedDialog('Slash Commands', 'Topic', InfoDialog, {
|
||||||
|
|
|
@ -24,10 +24,7 @@ const Modal = require('../../Modal');
|
||||||
const sdk = require('../../index');
|
const sdk = require('../../index');
|
||||||
const dis = require('../../dispatcher');
|
const dis = require('../../dispatcher');
|
||||||
|
|
||||||
const linkify = require('linkifyjs');
|
import { linkifyAndSanitizeHtml } from '../../HtmlUtils';
|
||||||
const linkifyString = require('linkifyjs/string');
|
|
||||||
const linkifyMatrix = require('../../linkify-matrix');
|
|
||||||
const sanitizeHtml = require('sanitize-html');
|
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
import { _t } from '../../languageHandler';
|
import { _t } from '../../languageHandler';
|
||||||
|
@ -37,8 +34,6 @@ import {instanceForInstanceId, protocolNameForInstanceId} from '../../utils/Dire
|
||||||
const MAX_NAME_LENGTH = 80;
|
const MAX_NAME_LENGTH = 80;
|
||||||
const MAX_TOPIC_LENGTH = 160;
|
const MAX_TOPIC_LENGTH = 160;
|
||||||
|
|
||||||
linkifyMatrix(linkify);
|
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
displayName: 'RoomDirectory',
|
displayName: 'RoomDirectory',
|
||||||
|
|
||||||
|
@ -438,7 +433,7 @@ module.exports = React.createClass({
|
||||||
if (topic.length > MAX_TOPIC_LENGTH) {
|
if (topic.length > MAX_TOPIC_LENGTH) {
|
||||||
topic = `${topic.substring(0, MAX_TOPIC_LENGTH)}...`;
|
topic = `${topic.substring(0, MAX_TOPIC_LENGTH)}...`;
|
||||||
}
|
}
|
||||||
topic = linkifyString(sanitizeHtml(topic));
|
topic = linkifyAndSanitizeHtml(topic);
|
||||||
|
|
||||||
rows.push(
|
rows.push(
|
||||||
<tr key={ rooms[i].room_id }
|
<tr key={ rooms[i].room_id }
|
||||||
|
|
|
@ -22,9 +22,6 @@ import ReactDOM from 'react-dom';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import highlight from 'highlight.js';
|
import highlight from 'highlight.js';
|
||||||
import * as HtmlUtils from '../../../HtmlUtils';
|
import * as HtmlUtils from '../../../HtmlUtils';
|
||||||
import * as linkify from 'linkifyjs';
|
|
||||||
import linkifyElement from 'linkifyjs/element';
|
|
||||||
import linkifyMatrix from '../../../linkify-matrix';
|
|
||||||
import sdk from '../../../index';
|
import sdk from '../../../index';
|
||||||
import ScalarAuthClient from '../../../ScalarAuthClient';
|
import ScalarAuthClient from '../../../ScalarAuthClient';
|
||||||
import Modal from '../../../Modal';
|
import Modal from '../../../Modal';
|
||||||
|
@ -38,8 +35,6 @@ import PushProcessor from 'matrix-js-sdk/lib/pushprocessor';
|
||||||
import ReplyThread from "../elements/ReplyThread";
|
import ReplyThread from "../elements/ReplyThread";
|
||||||
import {host as matrixtoHost} from '../../../matrix-to';
|
import {host as matrixtoHost} from '../../../matrix-to';
|
||||||
|
|
||||||
linkifyMatrix(linkify);
|
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
displayName: 'TextualBody',
|
displayName: 'TextualBody',
|
||||||
|
|
||||||
|
@ -98,7 +93,7 @@ module.exports = React.createClass({
|
||||||
// are still sent as plaintext URLs. If these are ever pillified in the composer,
|
// are still sent as plaintext URLs. If these are ever pillified in the composer,
|
||||||
// we should be pillify them here by doing the linkifying BEFORE the pillifying.
|
// we should be pillify them here by doing the linkifying BEFORE the pillifying.
|
||||||
this.pillifyLinks(this.refs.content.children);
|
this.pillifyLinks(this.refs.content.children);
|
||||||
linkifyElement(this.refs.content, linkifyMatrix.options);
|
HtmlUtils.linkifyElement(this.refs.content);
|
||||||
this.calculateUrlPreview();
|
this.calculateUrlPreview();
|
||||||
|
|
||||||
if (this.props.mxEvent.getContent().format === "org.matrix.custom.html") {
|
if (this.props.mxEvent.getContent().format === "org.matrix.custom.html") {
|
||||||
|
|
|
@ -16,19 +16,15 @@ limitations under the License.
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const React = require('react');
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import { linkifyElement } from '../../../HtmlUtils';
|
||||||
|
|
||||||
const sdk = require('../../../index');
|
const sdk = require('../../../index');
|
||||||
const MatrixClientPeg = require('../../../MatrixClientPeg');
|
const MatrixClientPeg = require('../../../MatrixClientPeg');
|
||||||
const ImageUtils = require('../../../ImageUtils');
|
const ImageUtils = require('../../../ImageUtils');
|
||||||
const Modal = require('../../../Modal');
|
const Modal = require('../../../Modal');
|
||||||
|
|
||||||
const linkify = require('linkifyjs');
|
|
||||||
const linkifyElement = require('linkifyjs/element');
|
|
||||||
const linkifyMatrix = require('../../../linkify-matrix');
|
|
||||||
linkifyMatrix(linkify);
|
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
displayName: 'LinkPreviewWidget',
|
displayName: 'LinkPreviewWidget',
|
||||||
|
|
||||||
|
@ -62,13 +58,13 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
if (this.refs.description) {
|
if (this.refs.description) {
|
||||||
linkifyElement(this.refs.description, linkifyMatrix.options);
|
linkifyElement(this.refs.description);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidUpdate: function() {
|
componentDidUpdate: function() {
|
||||||
if (this.refs.description) {
|
if (this.refs.description) {
|
||||||
linkifyElement(this.refs.description, linkifyMatrix.options);
|
linkifyElement(this.refs.description);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -17,15 +17,11 @@ limitations under the License.
|
||||||
import sdk from '../../../index';
|
import sdk from '../../../index';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { _t } from '../../../languageHandler';
|
import { _t } from '../../../languageHandler';
|
||||||
import * as linkify from 'linkifyjs';
|
import { linkifyElement } from '../../../HtmlUtils';
|
||||||
import linkifyElement from 'linkifyjs/element';
|
|
||||||
import linkifyMatrix from '../../../linkify-matrix';
|
|
||||||
import { ContentRepo } from 'matrix-js-sdk';
|
import { ContentRepo } from 'matrix-js-sdk';
|
||||||
import MatrixClientPeg from '../../../MatrixClientPeg';
|
import MatrixClientPeg from '../../../MatrixClientPeg';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
linkifyMatrix(linkify);
|
|
||||||
|
|
||||||
export function getDisplayAliasForRoom(room) {
|
export function getDisplayAliasForRoom(room) {
|
||||||
return room.canonicalAlias || (room.aliases ? room.aliases[0] : "");
|
return room.canonicalAlias || (room.aliases ? room.aliases[0] : "");
|
||||||
}
|
}
|
||||||
|
@ -53,7 +49,7 @@ export default React.createClass({
|
||||||
|
|
||||||
_linkifyTopic: function() {
|
_linkifyTopic: function() {
|
||||||
if (this.refs.topic) {
|
if (this.refs.topic) {
|
||||||
linkifyElement(this.refs.topic, linkifyMatrix.options);
|
linkifyElement(this.refs.topic);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -25,17 +25,13 @@ import MatrixClientPeg from '../../../MatrixClientPeg';
|
||||||
import Modal from "../../../Modal";
|
import Modal from "../../../Modal";
|
||||||
import RateLimitedFunc from '../../../ratelimitedfunc';
|
import RateLimitedFunc from '../../../ratelimitedfunc';
|
||||||
|
|
||||||
import * as linkify from 'linkifyjs';
|
import { linkifyElement } from '../../../HtmlUtils';
|
||||||
import linkifyElement from 'linkifyjs/element';
|
|
||||||
import linkifyMatrix from '../../../linkify-matrix';
|
|
||||||
import AccessibleButton from '../elements/AccessibleButton';
|
import AccessibleButton from '../elements/AccessibleButton';
|
||||||
import ManageIntegsButton from '../elements/ManageIntegsButton';
|
import ManageIntegsButton from '../elements/ManageIntegsButton';
|
||||||
import {CancelButton} from './SimpleRoomHeader';
|
import {CancelButton} from './SimpleRoomHeader';
|
||||||
import SettingsStore from "../../../settings/SettingsStore";
|
import SettingsStore from "../../../settings/SettingsStore";
|
||||||
import RoomHeaderButtons from '../right_panel/RoomHeaderButtons';
|
import RoomHeaderButtons from '../right_panel/RoomHeaderButtons';
|
||||||
|
|
||||||
linkifyMatrix(linkify);
|
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
displayName: 'RoomHeader',
|
displayName: 'RoomHeader',
|
||||||
|
|
||||||
|
@ -78,7 +74,7 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
componentDidUpdate: function() {
|
componentDidUpdate: function() {
|
||||||
if (this.refs.topic) {
|
if (this.refs.topic) {
|
||||||
linkifyElement(this.refs.topic, linkifyMatrix.options);
|
linkifyElement(this.refs.topic);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue