From 17762ed7b2c899b957f72be9c7f295ad4fbfbd90 Mon Sep 17 00:00:00 2001 From: Brett Sun Date: Mon, 13 Jun 2016 17:33:59 +0200 Subject: [PATCH] Move escapeHTML to dom utils --- js/components/ascribe_media/media_player.js | 2 +- js/utils/dom.js | 13 +++++++++++++ js/utils/general.js | 12 ------------ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/js/components/ascribe_media/media_player.js b/js/components/ascribe_media/media_player.js index fe0c61db..c58bc582 100644 --- a/js/components/ascribe_media/media_player.js +++ b/js/components/ascribe_media/media_player.js @@ -8,8 +8,8 @@ import audiojs from '../../third_party/imports/audiojs'; import shmui from '../../third_party/imports/shmui'; import videojs from '../../third_party/imports/videojs'; +import { escapeHTML } from '../../utils/dom'; import { extractFileExtensionFromUrl } from '../../utils/file'; -import { escapeHTML } from '../../utils/general'; /** diff --git a/js/utils/dom.js b/js/utils/dom.js index 8809bbf8..4f87ac54 100644 --- a/js/utils/dom.js +++ b/js/utils/dom.js @@ -4,6 +4,19 @@ import React from 'react'; import { getLinkRegex, isEmail } from './regex'; + +/** + * Escape HTML in a string so it can be injected safely using React's `dangerouslySetInnerHTML` + * + * @param {string} s String to be sanitized + * @return {string} Sanitized string + * + * Taken from: http://stackoverflow.com/a/17546215/597097 + */ +export function escapeHTML(s) { + return document.createElement('div').appendChild(document.createTextNode(s)).parentNode.innerHTML; +} + /** * Set the title in the browser window. */ diff --git a/js/utils/general.js b/js/utils/general.js index b74b3edf..f1789621 100644 --- a/js/utils/general.js +++ b/js/utils/general.js @@ -14,15 +14,3 @@ export { sanitizeList, selectFromObject } from 'js-utility-belt/es6'; - -/** - * Escape HTML in a string so it can be injected safely using - * React's `dangerouslySetInnerHTML` - * - * @param s the string to be sanitized - * - * Taken from: http://stackoverflow.com/a/17546215/597097 - */ -export function escapeHTML(s) { - return document.createElement('div').appendChild(document.createTextNode(s)).parentNode.innerHTML; -}