Skip to content

Commit

Permalink
fix: added file path check to ensure objects can be added with functi…
Browse files Browse the repository at this point in the history
…on converted strings
  • Loading branch information
niftylettuce committed Aug 17, 2020
1 parent 658d68a commit eb6a926
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"debug": "^4.1.1",
"human-interval": "^1.0.0",
"is-string-and-not-blank": "^0.0.2",
"is-valid-path": "^0.1.1",
"ms": "^2.1.2",
"safe-timers": "^1.1.0"
},
Expand Down
8 changes: 5 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const cron = require('cron-validate');
const debug = require('debug')('bree');
const humanInterval = require('human-interval');
const isSANB = require('is-string-and-not-blank');
const isValidPath = require('is-valid-path');
const later = require('@breejs/later');
const ms = require('ms');
const threads = require('bthreads');
Expand Down Expand Up @@ -103,7 +104,7 @@ class Bree extends EventEmitter {
// validate root (sync check)
if (isSANB(this.config.root)) {
/* istanbul ignore next */
if (hasFsStatSync) {
if (hasFsStatSync && isValidPath(this.config.root)) {
const stats = fs.statSync(this.config.root);
if (!stats.isDirectory())
throw new Error(
Expand Down Expand Up @@ -176,6 +177,7 @@ class Bree extends EventEmitter {

// eslint-disable-next-line complexity
validateJob(job, i, names, errors) {
if (typeof this.config.jobs[i] === 'undefined') this.config.jobs[i] = {};
// support a simple string which we will transform to have a path
if (isSANB(job)) {
// don't allow a job to have the `index` file name
Expand Down Expand Up @@ -215,7 +217,7 @@ class Bree extends EventEmitter {
);
try {
/* istanbul ignore next */
if (hasFsStatSync) {
if (hasFsStatSync && isValidPath(path)) {
const stats = fs.statSync(path);
if (!stats.isFile())
throw new Error(`Job #${i + 1} "${job}" path missing: ${path}`);
Expand Down Expand Up @@ -311,7 +313,7 @@ class Bree extends EventEmitter {
if (path) {
try {
/* istanbul ignore next */
if (hasFsStatSync) {
if (hasFsStatSync && isValidPath(path)) {
const stats = fs.statSync(path);
// eslint-disable-next-line max-depth
if (!stats.isFile())
Expand Down
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1656,3 +1656,10 @@ test('remove > fails if job does not exist', (t) => {

t.throws(() => bree.remove('basic'), { message: /Job .* does not exist/ });
});

test('add > successfully adds job object', (t) => {
const bree = new Bree({ root: false });
function noop() {}
bree.add({ name: 'basic', path: noop.toString() });
t.pass();
});
26 changes: 26 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4619,6 +4619,11 @@ is-extendable@^1.0.1:
dependencies:
is-plain-object "^2.0.4"

is-extglob@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-1.0.0.tgz#ac468177c4943405a092fc8f29760c6ffc6206c0"
integrity sha1-rEaBd8SUNAWgkvyPKXYMb/xiBsA=

is-extglob@^2.1.0, is-extglob@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2"
Expand All @@ -4642,6 +4647,13 @@ is-get-set-prop@^1.0.0:
get-set-props "^0.1.0"
lowercase-keys "^1.0.0"

is-glob@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-2.0.1.tgz#d096f926a3ded5600f3fdfd91198cb0888c2d863"
integrity sha1-0Jb5JqPe1WAPP9/ZEZjLCIjC2GM=
dependencies:
is-extglob "^1.0.0"

is-glob@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-3.1.0.tgz#7ba5ae24217804ac70707b96922567486cc3e84a"
Expand Down Expand Up @@ -4674,6 +4686,13 @@ is-interactive@^1.0.0:
resolved "https://registry.yarnpkg.com/is-interactive/-/is-interactive-1.0.0.tgz#cea6e6ae5c870a7b0a0004070b7b587e0252912e"
integrity sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w==

is-invalid-path@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/is-invalid-path/-/is-invalid-path-0.1.0.tgz#307a855b3cf1a938b44ea70d2c61106053714f34"
integrity sha1-MHqFWzzxqTi0TqcNLGEQYFNxTzQ=
dependencies:
is-glob "^2.0.0"

is-js-type@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/is-js-type/-/is-js-type-2.0.0.tgz#73617006d659b4eb4729bba747d28782df0f7e22"
Expand Down Expand Up @@ -4838,6 +4857,13 @@ is-url@^1.2.2:
resolved "https://registry.yarnpkg.com/is-url/-/is-url-1.2.4.tgz#04a4df46d28c4cff3d73d01ff06abeb318a1aa52"
integrity sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww==

is-valid-path@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/is-valid-path/-/is-valid-path-0.1.1.tgz#110f9ff74c37f663e1ec7915eb451f2db93ac9df"
integrity sha1-EQ+f90w39mPh7HkV60UfLbk6yd8=
dependencies:
is-invalid-path "^0.1.0"

is-whitespace-character@^1.0.0:
version "1.0.4"
resolved "https://registry.yarnpkg.com/is-whitespace-character/-/is-whitespace-character-1.0.4.tgz#0858edd94a95594c7c9dd0b5c174ec6e45ee4aa7"
Expand Down

0 comments on commit eb6a926

Please sign in to comment.