From 25772f1141f6561e13265d77f2649d86c2fbccd6 Mon Sep 17 00:00:00 2001 From: Keerthi Niranjan Date: Mon, 7 May 2018 14:50:31 +0530 Subject: [PATCH] ELECTRON-426 (Only first character of room name displays for the toast of room starting with '<" or '>' character) (#344) - Fixes html content in the notification title - Removes 'replaceStrongTag' and 'replaceHTMLTags' function and changing to innerHTML to innerText --- js/notify/electron-notify-preload.js | 6 ++-- js/notify/notifyImpl.js | 45 +--------------------------- 2 files changed, 4 insertions(+), 47 deletions(-) diff --git a/js/notify/electron-notify-preload.js b/js/notify/electron-notify-preload.js index c8202efa..5facd2f9 100644 --- a/js/notify/electron-notify-preload.js +++ b/js/notify/electron-notify-preload.js @@ -116,10 +116,10 @@ function setContents(event, notificationObj) { } // Title - titleDoc.innerHTML = notificationObj.title || ''; + titleDoc.innerText = notificationObj.title || ''; // message - messageDoc.innerHTML = notificationObj.text || ''; + messageDoc.innerText = notificationObj.text || ''; // Image if (notificationObj.image) { @@ -130,7 +130,7 @@ function setContents(event, notificationObj) { // Company if (notificationObj.company) { - companyDoc.innerHTML = notificationObj.company + companyDoc.innerText = notificationObj.company } else { messageDoc.style.marginTop = '15px'; } diff --git a/js/notify/notifyImpl.js b/js/notify/notifyImpl.js index 46946044..13a41ad9 100644 --- a/js/notify/notifyImpl.js +++ b/js/notify/notifyImpl.js @@ -33,10 +33,7 @@ class Notify { let emitter = new EventEmitter(); this.emitter = Queue(emitter); - // Replace strong html tags from the options.body - let message = replaceStrongTag(options.body); - // Replaces all html angle brackets w.r.t their entity name - message = replaceHTMLTags(message); + let message = options.body; this._id = notify({ title: title, @@ -246,44 +243,4 @@ function Queue(emitter) { return modifiedEmitter; } -/** - * Replace HTML tags <> from messages test to prevent - * HTML injection - * - * @param message {String} main text to display in notifications - * @return {void | string | *} - */ -function replaceHTMLTags(message) { - - if (typeof message !== 'string') { - return null; - } - - const tagsToReplace = { - '<': '<', - '>': '>' - }; - - function replaceTag(tag) { - return tagsToReplace[tag] || tag; - } - - return message.replace(/[<>]/g, replaceTag); -} - -/** - * Replace strong HTML tags from the string - * - * @param message {String} main text to display in notifications - * @return {void | string | *} - */ -function replaceStrongTag(message) { - - if (typeof message !== 'string') { - return null; - } - - return message.replace(/(?:)|(?:<\/strong>)+/g, ''); -} - module.exports = Notify;