nodejs/test/parallel/test-fs-buffertype-writesync.js
Ruben Bridgewater fb6df3bfac
fs: validate the input data to be of expected types
The input was not validated so far and that caused unwanted side
effects. E.g., `undefined` became the string `'undefined'`. It was
expected to fail or to end up as empty string.
Now all input is validated to be either some type of array buffer
view or a string. That way it's always clear what the user intents.

PR-URL: https://github.com/nodejs/node/pull/31030
Fixes: https://github.com/nodejs/node/issues/31025
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
2020-02-05 13:39:53 +01:00

17 lines
374 B
JavaScript

'use strict';
require('../common');
// This test ensures that writeSync throws for invalid data input.
const assert = require('assert');
const fs = require('fs');
[
true, false, 0, 1, Infinity, () => {}, {}, [], undefined, null
].forEach((value) => {
assert.throws(
() => fs.writeSync(1, value),
{ message: /"buffer"/, code: 'ERR_INVALID_ARG_TYPE' }
);
});