Socket
Socket
Sign inDemoInstall

node-notifier

Package Overview
Dependencies
4
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.3 to 2.0.4

test/notify-send.js

14

lib/notifiers/notify-send.js

@@ -20,10 +20,16 @@ /**

var allowedArguments = [
"urgency",
"expire",
"icon",
"category",
"hint"
];
var doNotification = function (options, callback) {
options.title = options.title || 'Node Notification:';
var initial = [options.title, options.message];
delete options.title;
delete options.message;
var argsList = utils.constructArgumentList(options, initial);
callback = callback || function (err, data) {};
var argsList = utils.constructArgumentList(options, initial, "-", allowedArguments);

@@ -37,2 +43,4 @@ utils.command(notifier, argsList, callback);

callback = callback || function () {};
options = options || {};

@@ -39,0 +47,0 @@ if (!options.message) {

@@ -26,12 +26,22 @@ var child_process = require('child_process')

module.exports.constructArgumentList = function (options, initial) {
var inArray = function (arr, val) {
for(var i = 0; i < arr.length; i++) {
if (arr[i] === val) {
return true;
}
}
return false;
};
module.exports.constructArgumentList = function (options, initial, keyExtra, allowedArguments) {
var args = [];
keyExtra = keyExtra || "";
var checkForAllowed = allowedArguments !== void 0;
(initial || []).forEach(function (val) {
args.push('"' + val + '"');
args.push('"' + escapeQuotes(val) + '"');
});
for(var key in options) {
if (options.hasOwnProperty(key)) {
args.push('-' + key, '"' + escapeQuotes(options[key]) + '"');
if (options.hasOwnProperty(key) && (!checkForAllowed || inArray(allowedArguments, key))) {
args.push('-' + keyExtra + key, '"' + escapeQuotes(options[key]) + '"');
}

@@ -38,0 +48,0 @@ }

{
"name": "node-notifier",
"version": "2.0.3",
"version": "2.0.4",
"description": "A Node.js module for sending notifications on mac, windows and linux",

@@ -5,0 +5,0 @@ "main": "index.js",

var NotificationCenter = require('../').NotificationCenter
, should = require('should')
, os = require('os')
, utils = require('../lib/utils')
, assert = require('assert');

@@ -11,3 +12,2 @@

if (os.type() !== 'Darwin') {
console.log('Only tests for Mac for now.');
return;

@@ -75,5 +75,59 @@ }

});
});
describe("arguments", function () {
before(function () {
this.original = utils.command;
});
after(function () {
utils.command = this.original;
});
it('should allow for non-sensical arguments (fail gracefully)', function (done) {
var expected = [ '-title', '"title"', '-message', '"body"', '-tullball', '"notValid"' ]
utils.command = function (notifier, argsList, callback) {
argsList.should.eql(expected);
done();
};
var notifier = new NotificationCenter();
notifier.isNotifyChecked = true;
notifier.hasNotifier = true;
notifier.notify({
title: "title",
message: "body",
tullball: "notValid"
}, function (err) {
should.not.exist(err);
done();
});
});
it('should escape all title andmessage', function (done) {
var expected = [ '-title', '"title \\"message\\""',
'-message', '"body \\"message\\""', '-tullball', '"notValid"' ]
utils.command = function (notifier, argsList, callback) {
argsList.should.eql(expected);
done();
};
var notifier = new NotificationCenter();
notifier.isNotifyChecked = true;
notifier.hasNotifier = true;
notifier.notify({
title: 'title "message"',
message: 'body "message"',
tullball: "notValid"
}, function (err) {
should.not.exist(err);
done();
});
});
});
});
}());
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc