aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Ai Hoshino <ambiguous404@gmail.com> 2023-07-22 22:10:36 +0800
committerGravatar GitHub <noreply@github.com> 2023-07-22 07:10:36 -0700
commit04d19d6f6a0765305cd85e137e1b834b1b0cc735 (patch)
tree68237e3a1a08af7585728f7cddf2e79e14b3f17c
parent3418feb2e99546efe033f72145a0ccc90c7e81ad (diff)
downloadbun-04d19d6f6a0765305cd85e137e1b834b1b0cc735.tar.gz
bun-04d19d6f6a0765305cd85e137e1b834b1b0cc735.tar.zst
bun-04d19d6f6a0765305cd85e137e1b834b1b0cc735.zip
Fix `writeFileSync` when the mode is greater than 0o777. (#3747)
Close: #3740
-rw-r--r--src/bun.js/node/types.zig6
-rw-r--r--test/js/node/fs/fs.test.ts7
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,