Skip to content

Commit

Permalink
Sanitize response on notify callback
Browse files Browse the repository at this point in the history
  • Loading branch information
MadLittleMods committed Feb 28, 2016
1 parent 905e063 commit a44454a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
14 changes: 9 additions & 5 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,15 @@ 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) {
fn.apply(emitter, [err, data]);
if (err || !mapper || !data) return;

var key = mapper(data);
return function (err, data) {
var cleanedData = data.toLowerCase().trim();
if(cleanedData.match(/^activate/)) {
cleanedData = 'activate';
}
fn.apply(emitter, [err, cleanedData]);
if (err || !mapper || !cleanedData) return;

var key = mapper(cleanedData);
if (!key) return;
emitter.emit(key, emitter, options);
};
Expand Down
7 changes: 3 additions & 4 deletions notifiers/balloon.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ WindowsBalloon.prototype.notify = function (options, callback) {
title: 'node-notifier',
message: options
};

var actionJackedCallback = utils.actionJackerDecorator(this, options, callback, function (data) {
var cleaned = data.toLowerCase().trim();
if (cleaned === 'activate') {
if (data === 'activate') {
return 'click';
}
if (cleaned === 'timeout') {
if (data === 'timeout') {
return 'timeout';
}
return false;
Expand Down
5 changes: 2 additions & 3 deletions notifiers/growl.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ Growl.prototype.notify = function (options, callback) {
};

callback = utils.actionJackerDecorator(this, options, callback, function (data) {
var cleaned = data.toLowerCase().trim();
if (cleaned === 'click') {
if (data === 'click') {
return 'click';
}
if (cleaned === 'timedout') {
if (data === 'timedout') {
return 'timeout';
}
return false;
Expand Down
5 changes: 2 additions & 3 deletions notifiers/notificationcenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ NotificationCenter.prototype.notify = function (options, callback) {
var actionJackedCallback = utils.actionJackerDecorator(this, options, callback, function (data) {
if (activeId !== id) return false;

var cleaned = data.toLowerCase().trim();
if (cleaned === 'activate') {
if (data === 'activate') {
return 'click';
}
if (cleaned === 'timeout') {
if (data === 'timeout') {
return 'timeout';
}
return false;
Expand Down
7 changes: 3 additions & 4 deletions notifiers/toaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ WindowsToaster.prototype.notify = function (options, callback) {
title: 'node-notifier',
message: options
};

var actionJackedCallback = utils.actionJackerDecorator(this, options, callback, function (data) {
var cleaned = data.toLowerCase().trim();
if (cleaned === 'activated') {
if (data === 'activate') {
return 'click';
}
if (cleaned === 'timeout') {
if (data === 'timeout') {
return 'timeout';
}
return false;
Expand Down

1 comment on commit a44454a

@gucong3000
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.