GeezerVison is showing github.com — fs: fix fs.read when passing null value · nodejs/node@b8b8e82
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/fs.js +6-4Lines changed: 6 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -485,10 +485,12 @@ function read(fd, buffer, offset, length, position, callback) { |
485 | 485 | callback = offset; |
486 | 486 | } |
487 | 487 |
|
488 | | - buffer = options.buffer || Buffer.alloc(16384); |
489 | | - offset = options.offset || 0; |
490 | | - length = options.length || buffer.length; |
491 | | - position = options.position; |
| 488 | + ({ |
| 489 | + buffer = Buffer.alloc(16384), |
| 490 | + offset = 0, |
| 491 | + length = buffer.length, |
| 492 | + position |
| 493 | + } = options); |
492 | 494 | } |
493 | 495 |
|
494 | 496 | validateBuffer(buffer); |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-fs-read.js +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -80,6 +80,14 @@ assert.throws( |
80 | 80 | } |
81 | 81 | ); |
82 | 82 |
|
| 83 | +['buffer', 'offset', 'length'].forEach((option) => |
| 84 | + assert.throws( |
| 85 | + () => fs.read(fd, { |
| 86 | + [option]: null |
| 87 | + }), |
| 88 | + `not throws when options.${option} is null` |
| 89 | + )); |
| 90 | + |
83 | 91 | assert.throws( |
84 | 92 | () => fs.read(null, Buffer.alloc(1), 0, 1, 0), |
85 | 93 | { |
|