From a034c12f5ce7c6e1e2e8a651d652cd77b87364a2 Mon Sep 17 00:00:00 2001 From: Brandon Rodriguez <brodriguez8774@gmail.com> Date: Thu, 17 Dec 2020 20:18:06 -0500 Subject: [PATCH] Add basic validation for passed logging directory value --- src/logging.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/logging.js b/src/logging.js index d1e07ae..25b45eb 100644 --- a/src/logging.js +++ b/src/logging.js @@ -60,6 +60,21 @@ class LoggingClass { */ constructor(logging_dir) { + // First validate passed logging value. Start by checking if string. + if (typeof logging_dir === 'string' || logging_dir instanceof String) { + // Is string. Validate. + logging_dir = logging_dir.trim(); + + // Check last character. + if (logging_dir.slice(-1) != '/') { + logging_dir += '/'; + } + + } else { + // Is not string. Raise error. + throw new Error('Logging class must be initialized with directory location.'); + } + // Attempt to create logging folder. fs.mkdir(logging_dir, err => { // Ignore "dir already exists" errors. Raise all others. -- GitLab