diff options
author | Voltrex <mohammadkeyvanzade94@gmail.com> | 2021-06-14 03:37:54 +0430 |
---|---|---|
committer | Antoine du Hamel <duhamelantoine1995@gmail.com> | 2021-06-26 16:34:13 +0200 |
commit | 1317252dfe8824fd9cfee125d2aaa94004db2f3b (patch) | |
tree | 411472e3b0b8304faa5b92b5b034236fd402cd5d /lib/fs.js | |
parent | 46a7e619005c10de01be2c439fe1ff6ca8df8054 (diff) | |
download | node-new-1317252dfe8824fd9cfee125d2aaa94004db2f3b.tar.gz |
fs: allow empty string for temp directory prefix
The `fs` lib module's `mkdtemp()` and `mkdtempSync()` methods were
missing a validator, and weren't allowing the empty string as a valid
prefix.
PR-URL: https://github.com/nodejs/node/pull/39028
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Diffstat (limited to 'lib/fs.js')
-rw-r--r-- | lib/fs.js | 12 |
1 files changed, 5 insertions, 7 deletions
@@ -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`; |