mirror of
https://github.com/denoland/deno.git
synced 2025-01-22 06:09:25 -05:00
fix(polyfill): correctly handle flag when its equal 0 (#20953)
Fixes https://github.com/denoland/deno/issues/20910
This commit is contained in:
parent
fb73eb1e9d
commit
9f9c3d9048
5 changed files with 29 additions and 4 deletions
|
@ -397,4 +397,14 @@ Deno.test("[std/node/fs] open callback isn't called twice if error is thrown", a
|
|||
await Deno.remove(tempFile);
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "SYNC: open file with flag set to 0 (readonly)",
|
||||
fn() {
|
||||
const file = Deno.makeTempFileSync();
|
||||
const fd = openSync(file, 0);
|
||||
assert(Deno.resources()[fd]);
|
||||
closeSync(fd);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
|
@ -306,3 +306,18 @@ Deno.test({
|
|||
await Deno.remove(file);
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "SYNC: read with no offsetOropts argument",
|
||||
fn() {
|
||||
const moduleDir = path.dirname(path.fromFileUrl(import.meta.url));
|
||||
const testData = path.resolve(moduleDir, "testdata", "hello.txt");
|
||||
const buffer = Buffer.alloc(1024);
|
||||
const fd = openSync(testData, "r");
|
||||
const _bytesRead = readSync(
|
||||
fd,
|
||||
buffer,
|
||||
);
|
||||
closeSync(fd);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -108,7 +108,7 @@ export function checkEncoding(encoding: Encodings | null): Encodings | null {
|
|||
export function getOpenOptions(
|
||||
flag: string | number | undefined,
|
||||
): Deno.OpenOptions {
|
||||
if (!flag) {
|
||||
if (flag === undefined) {
|
||||
return { create: true, append: true };
|
||||
}
|
||||
|
||||
|
|
|
@ -57,8 +57,8 @@ function convertFlagAndModeToOptions(
|
|||
flag?: openFlags,
|
||||
mode?: number,
|
||||
): Deno.OpenOptions | undefined {
|
||||
if (!flag && !mode) return undefined;
|
||||
if (!flag && mode) return { mode };
|
||||
if (flag === undefined && mode === undefined) return undefined;
|
||||
if (flag === undefined && mode) return { mode };
|
||||
return { ...getOpenOptions(flag), mode };
|
||||
}
|
||||
|
||||
|
|
|
@ -167,7 +167,7 @@ export function readSync(
|
|||
if (typeof offsetOrOpt === "number") {
|
||||
offset = offsetOrOpt;
|
||||
validateInteger(offset, "offset", 0);
|
||||
} else {
|
||||
} else if (offsetOrOpt !== undefined) {
|
||||
const opt = offsetOrOpt as readSyncOptions;
|
||||
offset = opt.offset ?? 0;
|
||||
length = opt.length ?? buffer.byteLength;
|
||||
|
|
Loading…
Add table
Reference in a new issue