Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issues 113 & 114 #115

Merged
merged 2 commits into from
May 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!key) return;
emitter.emit(key, emitter, options);
};
Expand All @@ -193,7 +193,15 @@ 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);
}
if(typeof arg === 'string'){
arg = arg.replace(/\r?\n/g, '\\n');
}
return arg;
}

initial.forEach(function (val) {
args.push(wrapper + escapeFn(val) + wrapper);
Expand Down
4 changes: 2 additions & 2 deletions test/notify-send.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
22 changes: 22 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

});

});