Skip to content

Commit

Permalink
worker: simplify filename checks
Browse files Browse the repository at this point in the history
Replace a couple of checks with a single regular expression.

PR-URL: #27233
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
  • Loading branch information
BridgeAR authored and ZYSzys committed Apr 17, 2019
1 parent c61c722 commit 5450e48
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions lib/internal/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5450e48

Please sign in to comment.