mirror of
https://github.com/nodejs/node.git
synced 2025-04-30 23:56:58 +00:00

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>
34 lines
620 B
JavaScript
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);
|
|
});
|