From 6b658416cb9a28f2d36e5351fdfce24ed341be06 Mon Sep 17 00:00:00 2001 From: Voltrex Date: Mon, 14 Jun 2021 03:37:54 +0430 Subject: [PATCH] fs: use missing validator The `fs` lib module's `mkdtemp()` and `mkdtempSync()` methods are missing a validator. --- lib/fs.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 46209a3f4d58c0..cf3c885b31cdf8 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -74,7 +74,6 @@ const { codes: { ERR_FS_FILE_TOO_LARGE, ERR_INVALID_ARG_VALUE, - ERR_INVALID_ARG_TYPE, ERR_FEATURE_UNAVAILABLE_ON_PLATFORM, }, AbortError, @@ -136,6 +135,7 @@ const { validateEncoding, validateFunction, validateInteger, + validateString, } = require('internal/validators'); const watchers = require('internal/fs/watchers'); @@ -2712,9 +2712,8 @@ realpath.native = (path, options, callback) => { function mkdtemp(prefix, options, callback) { callback = makeCallback(typeof options === 'function' ? options : callback); options = getOptions(options, {}); - if (!prefix || typeof prefix !== 'string') { - throw new ERR_INVALID_ARG_TYPE('prefix', 'string', prefix); - } + + validateString(prefix, 'prefix'); nullCheck(prefix, 'prefix'); warnOnNonPortableTemplate(prefix); const req = new FSReqCallback(); @@ -2730,9 +2729,8 @@ function mkdtemp(prefix, options, callback) { */ function mkdtempSync(prefix, options) { options = getOptions(options, {}); - if (!prefix || typeof prefix !== 'string') { - throw new ERR_INVALID_ARG_TYPE('prefix', 'string', prefix); - } + + validateString(prefix, 'prefix'); nullCheck(prefix, 'prefix'); warnOnNonPortableTemplate(prefix); const path = `${prefix}XXXXXX`;