diff --git a/src/bunfig.zig b/src/bunfig.zig index 12c123522c..428f43f314 100644 --- a/src/bunfig.zig +++ b/src/bunfig.zig @@ -1163,7 +1163,7 @@ pub const Bunfig = struct { pub fn parse(allocator: std.mem.Allocator, source: *const logger.Source, ctx: Command.Context, comptime cmd: Command.Tag) !void { const log_count = ctx.log.errors + ctx.log.warnings; - const expr = if (strings.eqlComptime(source.path.name.ext[1..], "toml")) TOML.parse(source, ctx.log, allocator, true) catch |err| { + const expr = if (strings.eqlComptime(source.path.name.ext, ".toml")) TOML.parse(source, ctx.log, allocator, true) catch |err| { if (ctx.log.errors + ctx.log.warnings == log_count) { try ctx.log.addErrorOpts("Failed to parse", .{ .source = source, diff --git a/test/cli/bun.test.ts b/test/cli/bun.test.ts index c6dd62858f..780475c290 100644 --- a/test/cli/bun.test.ts +++ b/test/cli/bun.test.ts @@ -76,5 +76,22 @@ describe("bun", () => { fs.unlinkSync(path); } }); + + test("test --config=NUL on Windows should not panic", () => { + // On Windows, NUL is a special device file (like /dev/null on Unix) + // Using it as --config should not cause a panic due to empty extension slicing + const configPath = process.platform === "win32" ? "NUL" : "/dev/null"; + const p = Bun.spawnSync({ + cmd: [bunExe(), `--config=${configPath}`], + env: {}, + stderr: "pipe", + stdout: "pipe", + }); + // Should not panic - may fail to parse, but should not crash + // Exit code doesn't matter as long as it doesn't panic + const stderr = p.stderr?.toString() || ""; + expect(stderr).not.toContain("panic:"); + expect(stderr).not.toContain("start index 1 is larger than end index 0"); + }); }); });