mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
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:
@@ -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,
|
||||
|
||||
27
test/regression/issue/26530.test.ts
Normal file
27
test/regression/issue/26530.test.ts
Normal 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);
|
||||
});
|
||||
Reference in New Issue
Block a user