diff options
-rw-r--r-- | src/bun.js/node/types.zig | 6 | ||||
-rw-r--r-- | test/js/node/fs/fs.test.ts | 7 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index 54fdc6247..03e45f471 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -1005,12 +1005,12 @@ pub fn modeFromJS(ctx: JSC.C.JSContextRef, value: JSC.JSValue, exception: JSC.C. }; }; - if (mode_int < 0 or mode_int > 0o777) { - JSC.throwInvalidArguments("Invalid mode: must be an octal number", .{}, ctx, exception); + if (mode_int < 0) { + JSC.throwInvalidArguments("Invalid mode: must be greater than or equal to 0.", .{}, ctx, exception); return null; } - return mode_int; + return mode_int & 0o777; } pub const PathOrFileDescriptor = union(Tag) { diff --git a/test/js/node/fs/fs.test.ts b/test/js/node/fs/fs.test.ts index 48aa9d3b9..f86c9fdce 100644 --- a/test/js/node/fs/fs.test.ts +++ b/test/js/node/fs/fs.test.ts @@ -548,7 +548,12 @@ describe("writeFileSync", () => { expect(readFileSync(path, "utf8")).toBe("File written successfully"); }); - + it("write file with mode, issue #3740", () => { + const path = `${tmpdir()}/${Date.now()}.writeFileSyncWithMode.txt`; + writeFileSync(path, "bun", { mode: 33188 }); + const stat = fs.statSync(path); + expect(stat.mode).toBe(33188); + }); it("returning Buffer works", () => { const buffer = new Buffer([ 70, 105, 108, 101, 32, 119, 114, 105, 116, 116, 101, 110, 32, 115, 117, 99, 99, 101, 115, 115, 102, 117, 108, 108, |