aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/node/types.zig12
-rw-r--r--test/js/node/fs/fs.test.ts17
2 files changed, 19 insertions, 10 deletions
diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig
index 84dc394d0..72f1dff7e 100644
--- a/src/bun.js/node/types.zig
+++ b/src/bun.js/node/types.zig
@@ -881,11 +881,7 @@ pub const Valid = struct {
pub fn pathSlice(zig_str: JSC.ZigString.Slice, ctx: JSC.C.JSContextRef, exception: JSC.C.ExceptionRef) bool {
switch (zig_str.len) {
- 0 => {
- JSC.throwInvalidArguments("Invalid path string: can't be empty", .{}, ctx, exception);
- return false;
- },
- 1...bun.MAX_PATH_BYTES => return true,
+ 0...bun.MAX_PATH_BYTES => return true,
else => {
// TODO: should this be an EINVAL?
JSC.throwInvalidArguments(
@@ -903,11 +899,7 @@ pub const Valid = struct {
pub fn pathStringLength(len: usize, ctx: JSC.C.JSContextRef, exception: JSC.C.ExceptionRef) bool {
switch (len) {
- 0 => {
- JSC.throwInvalidArguments("Invalid path string: can't be empty", .{}, ctx, exception);
- return false;
- },
- 1...bun.MAX_PATH_BYTES => return true,
+ 0...bun.MAX_PATH_BYTES => return true,
else => {
// TODO: should this be an EINVAL?
JSC.throwInvalidArguments(
diff --git a/test/js/node/fs/fs.test.ts b/test/js/node/fs/fs.test.ts
index 41275edd5..3e030f609 100644
--- a/test/js/node/fs/fs.test.ts
+++ b/test/js/node/fs/fs.test.ts
@@ -953,6 +953,23 @@ describe("stat", () => {
} catch (e: any) {
expect(e.code).toBe("ENOENT");
}
+
+ try {
+ statSync("");
+ throw "statSync should throw";
+ } catch (e: any) {
+ expect(e.code).toBe("ENOENT");
+ }
+ });
+});
+
+describe("exist", () => {
+ it("should return false with invalid path", () => {
+ expect(existsSync("/pathNotExist")).toBe(false);
+ });
+
+ it("should return false with empty string", () => {
+ expect(existsSync("")).toBe(false);
});
});