fix(bunfig): handle config files with no extension

When a config file path has no extension (e.g., Windows device files
like NUL, CON, PRN), the code would panic with "start index 1 is larger
than end index 0" because it tried to slice ext[1..] on an empty string.

Use the safe extWithoutLeadingDot() method instead, which properly
handles empty extensions.

Fixes #26530

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Claude Bot
2026-01-28 12:34:15 +00:00
parent ba426210c2
commit 4e66dd492c
2 changed files with 28 additions and 1 deletions

View File

@@ -1204,7 +1204,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.extWithoutLeadingDot(), "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,

View File

@@ -0,0 +1,27 @@
import { expect, test } from "bun:test";
import { bunEnv, bunExe, tempDir } from "harness";
// Regression test for https://github.com/oven-sh/bun/issues/26530
// Bun should not panic when given a config file path with no extension
test("config file with no extension should not crash", async () => {
using dir = tempDir("issue-26530", {
"index.js": `console.log("ok")`,
// Create a config file with no extension
"myconfig": `{ "install": { "registry": "https://registry.npmjs.org" } }`,
});
// Using a config file with no extension should not cause a panic
await using proc = Bun.spawn({
cmd: [bunExe(), "run", "--config=myconfig", "index.js"],
cwd: String(dir),
env: bunEnv,
stdout: "pipe",
stderr: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
// Verify the script ran successfully and produced expected output
expect(stdout).toContain("ok");
expect(exitCode).toBe(0);
});