Skip to content

Commit

Permalink
Unescape strings from xml for notifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
shumingch committed Jun 4, 2017
1 parent 91fc4c6 commit 46e1a02
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions GmailNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,25 @@ const GLib = imports.gi.GLib;
const Gio = imports.gi.Gio;
const Config = imports.misc.config;

const escaped_one_to_xml_special_map = {
'&': '&',
''': "'",
'"': '"',
'&lt;': '<',
'&gt;': '>'
};
const unescape_regex = /(&quot;|&#39;|&lt;|&gt;|&amp;)/g;

const GmailNotification = new Lang.Class({
Name: 'GmailNotification',
Extends: MessageTray.Notification,

_init: function (source, content, iconName) {
try {
const date = new Date(content.date);
const title = content.subject;
const title = this._unescapeXML(content.subject);
const gicon = new Gio.ThemedIcon({name: iconName});
let banner = content.from;
let banner = this._unescapeXML(content.from);
const params = {
gicon: gicon
};
Expand All @@ -56,11 +65,15 @@ const GmailNotification = new Lang.Class({
console.error(err);
}
},
_addDateTimeToBanner: function(date, banner){
_unescapeXML: function (string) {
return string.replace(unescape_regex,
(str, item) => escaped_one_to_xml_special_map[item]);
},
_addDateTimeToBanner: function (date, banner) {
const locale_date = date.toLocaleFormat("%b %d %H:%M %p");
return locale_date + " " + banner;
},
_addDateTimeToParams: function(date, params){
_addDateTimeToParams: function (date, params) {
const unix_local = date.getTime() / 1000;
params.datetime = GLib.DateTime.new_from_unix_local(unix_local);
}
Expand Down

0 comments on commit 46e1a02

Please sign in to comment.