From 5450e48f6931d7960da88a96ddaab9f19dd4c788 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Mon, 15 Apr 2019 01:50:58 +0200 Subject: [PATCH] worker: simplify filename checks Replace a couple of checks with a single regular expression. PR-URL: https://github.com/nodejs/node/pull/27233 Reviewed-By: Richard Lau Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Yongsheng Zhang --- lib/internal/worker.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/internal/worker.js b/lib/internal/worker.js index 53e3c7668c31a0..796d1713dd510a 100644 --- a/lib/internal/worker.js +++ b/lib/internal/worker.js @@ -68,11 +68,7 @@ class Worker extends EventEmitter { options.execArgv); } if (!options.eval) { - if (!path.isAbsolute(filename) && - !filename.startsWith('./') && - !filename.startsWith('../') && - !filename.startsWith('.' + path.sep) && - !filename.startsWith('..' + path.sep)) { + if (!path.isAbsolute(filename) && !/^\.\.?[\\/]/.test(filename)) { throw new ERR_WORKER_PATH(filename); } filename = path.resolve(filename);