fs: fix fs.read when passing null value

PR-URL: https://github.com/nodejs/node/pull/32479
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
This commit is contained in:
himself65 authored and Anna Henningsen committed 2020-03-30 17:10:25 +02:00
1 parent fb254d2a83
commit defbc2ed82
2 files changed
+14 -4

No files matched your search

+6 -4
View File
@@ -484,10 +484,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);
+8
View File
@@ -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),
{