diff --git a/lib/fs.js b/lib/fs.js index fc430b5621f27d..3e253ef8c68979 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -481,10 +481,12 @@ function read(fd, buffer, offset, length, position, callback) { callback = offset; } - buffer = options.buffer || Buffer.alloc(16384); - offset = options.offset || 0; - length = options.length || buffer.length; - position = options.position; + ({ + buffer = Buffer.alloc(16384), + offset = 0, + length = buffer.length, + position + } = options); } validateBuffer(buffer); diff --git a/test/parallel/test-fs-read.js b/test/parallel/test-fs-read.js index 03ddf7f36d1f98..2b665d8eb96ebb 100644 --- a/test/parallel/test-fs-read.js +++ b/test/parallel/test-fs-read.js @@ -80,6 +80,14 @@ assert.throws( } ); +['buffer', 'offset', 'length'].forEach((option) => + assert.throws( + () => fs.read(fd, { + [option]: null + }), + `not throws when options.${option} is null` + )); + assert.throws( () => fs.read(null, Buffer.alloc(1), 0, 1, 0), {