node/test/parallel/test-fs-stream-options.js
Dylan Elliott d4693ff430 fs: add validation for fd and path
Adds type validation to options fd & opts in `fs.createWriteStream` and
`fs.createReadStream`.

Fixes: https://github.com/nodejs/node/issues/35178

PR-URL: https://github.com/nodejs/node/pull/35187
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
2021-03-20 19:10:39 +01:00

50 lines
742 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const fs = require('fs');
{
const fd = 'k';
assert.throws(
() => {
fs.createReadStream(null, { fd });
},
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
});
assert.throws(
() => {
fs.createWriteStream(null, { fd });
},
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
});
}
{
const path = 46;
assert.throws(
() => {
fs.createReadStream(path);
},
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
});
assert.throws(
() => {
fs.createWriteStream(path);
},
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
});
}