From 7cfd3870d555bb491855f1a4d2498a4c31218e80 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Mon, 18 Mar 2019 12:10:56 -0700 Subject: [PATCH] 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. --- js/notifications.js | 11 ++++++++++- preload.js | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/js/notifications.js b/js/notifications.js index f5900592c..2abb9d6c2 100644 --- a/js/notifications.js +++ b/js/notifications.js @@ -22,6 +22,15 @@ MESSAGE: 'message', }; + function filter(text) { + return (text || '') + .replace(/&/g, '&') + .replace(/"/g, '"') + .replace(/'/g, ''') + .replace(//g, '>'); + } + 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, }); diff --git a/preload.js b/preload.js index cd232c8c6..3c2c8d407 100644 --- a/preload.js +++ b/preload.js @@ -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;