Escape XML delimiters for notifications on linux

Thanks to @whitequark for pointing out an inconsistency in the way that
some Linux desktop environments were displaying markup in notifications.
This commit is contained in:
Scott Nonnenberg 2019-03-18 12:10:56 -07:00
parent 5336c5fd90
commit 7cfd3870d5
2 changed files with 11 additions and 1 deletions

View file

@ -22,6 +22,15 @@
MESSAGE: 'message',
};
function filter(text) {
return (text || '')
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}
Whisper.Notifications = new (Backbone.Collection.extend({
initialize() {
this.isEnabled = false;
@ -138,7 +147,7 @@
drawAttention();
this.lastNotification = new Notification(title, {
body: message,
body: window.platform === 'linux' ? filter(message) : message,
icon: iconUrl,
silent: !status.shouldPlayNotificationSound,
});

View file

@ -19,6 +19,7 @@ if (config.appInstance) {
title += ` - ${config.appInstance}`;
}
window.platform = process.platform;
window.getTitle = () => title;
window.getEnvironment = () => config.environment;
window.getAppInstance = () => config.appInstance;