Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
607bc74
module: support pattern trailers
guybedford Aug 2, 2021
2c36596
module: support pattern trailers for imports field
guybedford Sep 8, 2021
0d448ea
crypto: make FIPS related options always available
voxik Aug 25, 2020
cede1f2
deps: add -fno-strict-aliasing flag to libuv
danbev Nov 16, 2021
59da7c1
deps: upgrade openssl sources to 1.1.1m
richardlau Dec 14, 2021
3089326
deps: update archs files for OpenSSL-1.1.1m
richardlau Dec 14, 2021
2755d39
deps: update ICU to 70.1
targos Oct 29, 2021
b050c65
src: add option to disable loading native addons
d3lm Sep 13, 2021
a90defe
esm: make `process.exit()` default to exit code 0
MoonBall Jan 14, 2022
e903798
doc: add note regarding unfinished TLA
aduh95 Jan 10, 2022
5971d58
doc: add missing YAML tag in `esm.md`
aduh95 Jan 14, 2022
b85aa5a
deps: upgrade npm to 6.14.16
ruyadorno Jan 19, 2022
737df75
deps: add corepack
arcanis Sep 28, 2020
cd20ecc
deps: upgrade Corepack to 0.10
arcanis Oct 8, 2021
0231ffa
build: add `--without-corepack`
jonahsnider Dec 5, 2021
fc328f1
fs: nullish coalescing to respect zero positional reads
mihilmy Nov 3, 2021
f74fe2a
src: make napi_create_reference accept symbol
JckXia Aug 29, 2021
c1695ac
tools: update certdata.txt
richardlau Oct 1, 2021
5389b8a
crypto: update root certificates
richardlau Oct 1, 2021
625be75
lib: add return value for DC channel.unsubscribe
simon-id Oct 19, 2021
004eafb
lib: add unsubscribe method to non-active DC channels
simon-id Oct 19, 2021
4477da8
doc: fix corepack grammar for `--force` flag
styfle Nov 8, 2021
9beb4f8
2022-02-01, Version 14.19.0 'Fermium' (LTS)
richardlau Jan 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fs: nullish coalescing to respect zero positional reads
When the file read position is moved passing zero is
not respected and `null` is used instead. PR fixes the
issues by using nullish coalescing which will return
the rhs only when the lhs is `null` or `undefined`;
respecting the zero.

Fixes: #40715

PR-URL: #40716
Fixes: #40699
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Evan Lucas <evanlucas@me.com>
  • Loading branch information
mihilmy authored and richardlau committed Jan 25, 2022
commit fc328f1ab07cdd8f194181fb06e1750447da0f85
2 changes: 1 addition & 1 deletion lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ async function read(handle, bufferOrOptions, offset, length, position) {
}
offset = bufferOrOptions.offset || 0;
length = buffer.byteLength;
position = bufferOrOptions.position || null;
position = bufferOrOptions.position ?? null;
}

if (offset == null) {
Expand Down
19 changes: 19 additions & 0 deletions test/parallel/test-fs-promises-file-handle-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ async function validateReadNoParams() {
}

let useConf = false;
// Validates that the zero position is respected after the position has been
// moved. The test iterates over the xyz chars twice making sure that the values
// are read from the correct position.
async function validateReadWithPositionZero() {
const opts = { useConf: true };
const filePath = fixtures.path('x.txt');
const fileHandle = await open(filePath, 'r');
const expectedSequence = ['x', 'y', 'z'];

for (let i = 0; i < expectedSequence.length * 2; i++) {
const len = 1;
const pos = i % 3;
const buf = Buffer.alloc(len);
const { bytesRead } = await read(fileHandle, buf, 0, len, pos, opts);
assert.strictEqual(bytesRead, len);
assert.strictEqual(buf.toString(), expectedSequence[pos]);
}
}

(async function() {
for (const value of [false, true]) {
Expand All @@ -80,4 +98,5 @@ let useConf = false;
.then(common.mustCall());
}
await validateReadNoParams();
await validateReadWithPositionZero();
})().then(common.mustCall());