mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-11-30 12:43:59 -06:00
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:
parent
082575e22d
commit
25772f1141
@ -116,10 +116,10 @@ function setContents(event, notificationObj) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Title
|
// Title
|
||||||
titleDoc.innerHTML = notificationObj.title || '';
|
titleDoc.innerText = notificationObj.title || '';
|
||||||
|
|
||||||
// message
|
// message
|
||||||
messageDoc.innerHTML = notificationObj.text || '';
|
messageDoc.innerText = notificationObj.text || '';
|
||||||
|
|
||||||
// Image
|
// Image
|
||||||
if (notificationObj.image) {
|
if (notificationObj.image) {
|
||||||
@ -130,7 +130,7 @@ function setContents(event, notificationObj) {
|
|||||||
|
|
||||||
// Company
|
// Company
|
||||||
if (notificationObj.company) {
|
if (notificationObj.company) {
|
||||||
companyDoc.innerHTML = notificationObj.company
|
companyDoc.innerText = notificationObj.company
|
||||||
} else {
|
} else {
|
||||||
messageDoc.style.marginTop = '15px';
|
messageDoc.style.marginTop = '15px';
|
||||||
}
|
}
|
||||||
|
@ -33,10 +33,7 @@ class Notify {
|
|||||||
let emitter = new EventEmitter();
|
let emitter = new EventEmitter();
|
||||||
this.emitter = Queue(emitter);
|
this.emitter = Queue(emitter);
|
||||||
|
|
||||||
// Replace strong html tags from the options.body
|
let message = options.body;
|
||||||
let message = replaceStrongTag(options.body);
|
|
||||||
// Replaces all html angle brackets w.r.t their entity name
|
|
||||||
message = replaceHTMLTags(message);
|
|
||||||
|
|
||||||
this._id = notify({
|
this._id = notify({
|
||||||
title: title,
|
title: title,
|
||||||
@ -246,44 +243,4 @@ function Queue(emitter) {
|
|||||||
return modifiedEmitter;
|
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>)|(?:<\/strong>)+/g, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Notify;
|
module.exports = Notify;
|
||||||
|
Loading…
Reference in New Issue
Block a user