node/test/parallel/test-fs-mkdtemp-prefix-check.js
Voltrex 1317252dfe 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>
2021-06-26 16:34:13 +02:00

34 lines
620 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const prefixValues = [undefined, null, 0, true, false, 1];
function fail(value) {
assert.throws(
() => {
fs.mkdtempSync(value, {});
},
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError'
});
}
function failAsync(value) {
assert.throws(
() => {
fs.mkdtemp(value, common.mustNotCall());
},
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError'
});
}
prefixValues.forEach((prefixValue) => {
fail(prefixValue);
failAsync(prefixValue);
});