From 426fe77d514363a320c2b8c82d00bef09f69bc68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=BA?= Date: Wed, 13 Apr 2016 10:16:34 +0800 Subject: [PATCH 1/2] https://github.com/mikaelbr/node-notifier/issues/114 https://github.com/mikaelbr/node-notifier/issues/113 --- lib/utils.js | 47 +++++++++++++++++++++++++-------------------- test/notify-send.js | 4 ++-- test/utils.js | 22 +++++++++++++++++++++ 3 files changed, 50 insertions(+), 23 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 55f79b4..cab7765 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -125,14 +125,14 @@ module.exports.mapToNotifySend = function (options) { module.exports.mapToGrowl = function (options) { options = mapAppIcon(options); options = mapIconShorthand(options); - - if (options.text) { - options.message = options.text; - delete options.text; - } + options = mapText(options); if (options.icon && !Buffer.isBuffer(options.icon)) { - options.icon = fs.readFileSync(options.icon); + try { + options.icon = fs.readFileSync(options.icon); + }catch(ex){ + + } } return options; @@ -161,20 +161,20 @@ module.exports.mapToMac = function (options) { module.exports.actionJackerDecorator = function (emitter, options, fn, mapper) { options = clone(options); fn = fn || function (err, data) {}; - return function (err, data) { - - var resultantData = data; - // Sanitize the data - if(resultantData) { - resultantData = resultantData.toLowerCase().trim(); - if(resultantData.match(/^activate/)) { - resultantData = 'activate'; - } - } - fn.apply(emitter, [err, resultantData]); - if (err || !mapper || !resultantData) return; - - var key = mapper(resultantData); + return function (err, data) { + + var resultantData = data; + // Sanitize the data + if(resultantData) { + resultantData = resultantData.toLowerCase().trim(); + if(resultantData.match(/^activate/)) { + resultantData = 'activate'; + } + } + fn.apply(emitter, [err, resultantData]); + if (err || !mapper || !resultantData) return; + + var key = mapper(resultantData); if (!key) return; emitter.emit(key, emitter, options); }; @@ -193,7 +193,12 @@ module.exports.constructArgumentList = function (options, extra) { var explicitTrue = !!extra.explicitTrue; var wrapper = extra.wrapper === void 0 ? '"' : extra.wrapper; - var escapeFn = noEscape ? function (i) { return i; } : escapeQuotes; + var escapeFn = function(arg) { + if (!noEscape) { + arg = escapeQuotes(arg); + } + return arg.replace(/\r?\n/g, '\\n'); + } initial.forEach(function (val) { args.push(wrapper + escapeFn(val) + wrapper); diff --git a/test/notify-send.js b/test/notify-send.js index 2cc64d8..b3479af 100644 --- a/test/notify-send.js +++ b/test/notify-send.js @@ -75,7 +75,7 @@ describe('notify-send', function(){ it('should escape message input', function (done) { - var expected = [ '"Node Notification:"', '"some \\"me\'ss\\`age\\`\\""' ]; + var expected = [ '"Node Notification:"', '"some\\n \\"me\'ss\\`age\\`\\""' ]; utils.command = function (notifier, argsList, callback) { argsList.should.eql(expected); @@ -85,7 +85,7 @@ describe('notify-send', function(){ var notifier = new Notify({ suppressOsdCheck: true }); notifier.notify({ - message: 'some "me\'ss`age`"' + message: 'some\n "me\'ss`age`"' }, function (err) { should.not.exist(err); done(); diff --git a/test/utils.js b/test/utils.js index 6939cce..77fff36 100644 --- a/test/utils.js +++ b/test/utils.js @@ -96,6 +96,28 @@ describe('utils', function(){ (Buffer.isBuffer(obj.icon)).should.be.true; }); + it('should not map icon url for growl', function () { + var icon = 'http://hostname.com/logo.png'; + + var expected = { + title: 'Foo', + message: 'Bar', + icon: icon + }; + + _.mapToGrowl({ + title: 'Foo', + message: 'Bar', + icon: icon + }).should.eql(expected); + + _.mapToGrowl({ + title: 'Foo', + message: 'Bar', + appIcon: icon + }).should.eql(expected); + }); + }); }); From 8ef0bb2b332ab7ade591d4dbdacdf9434529e58e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=BA?= Date: Tue, 3 May 2016 08:48:32 +0800 Subject: [PATCH 2/2] fix arg error --- lib/utils.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index cab7765..08b80e3 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -197,7 +197,10 @@ module.exports.constructArgumentList = function (options, extra) { if (!noEscape) { arg = escapeQuotes(arg); } - return arg.replace(/\r?\n/g, '\\n'); + if(typeof arg === 'string'){ + arg = arg.replace(/\r?\n/g, '\\n'); + } + return arg; } initial.forEach(function (val) {