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
This commit is contained in:
Keerthi Niranjan 2018-05-07 14:50:31 +05:30 committed by Vishwas Shashidhar
parent 082575e22d
commit 25772f1141
2 changed files with 4 additions and 47 deletions

View File

@ -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';
}

View File

@ -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 = {
'<': '&lt;',
'>': '&gt;'
};
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>)|(?:<\/strong>)+/g, '');
}
module.exports = Notify;