diff --git a/src/install/install.zig b/src/install/install.zig index b8509f50ae221d..91674b95d5879a 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -231,7 +231,7 @@ const NetworkTask = struct { scope.url.displayProtocol(), scope.url.displayHostname(), port_number, - pathname, + strings.withoutTrailingSlash(pathname), name, }, ); @@ -242,7 +242,7 @@ const NetworkTask = struct { .{ scope.url.displayProtocol(), scope.url.displayHostname(), - pathname, + strings.withoutTrailingSlash(pathname), name, }, ); diff --git a/test/cli/install/bun-install-pathname-trailing-slash.test.ts b/test/cli/install/bun-install-pathname-trailing-slash.test.ts new file mode 100644 index 00000000000000..8cc34fe5928419 --- /dev/null +++ b/test/cli/install/bun-install-pathname-trailing-slash.test.ts @@ -0,0 +1,58 @@ +import { sleep } from "bun"; +import { expect, test } from "bun:test"; +import { mkdirSync, mkdtempSync, rmSync } from "fs"; +import { bunEnv, bunExe } from "harness"; +import { tmpdir } from "os"; +import { join } from "path"; + +// https://github.com/oven-sh/bun/issues/2462 +test("custom registry doesn't have multiple trailing slashes in pathname", async () => { + var urls: string[] = []; + + var server = Bun.serve({ + port: 0, + async fetch(req) { + urls.push(req.url); + return new Response("ok"); + }, + }); + const { port, hostname } = server; + const package_dir = join(tmpdir(), mkdtempSync("bun-install-path")); + try { + mkdirSync(package_dir, { recursive: true }); + } catch {} + await Bun.write( + join(package_dir, "bunfig.toml"), + ` +[install] +cache = false +registry = "http://${hostname}:${port}/prefixed-route/" +`, + ); + await Bun.write( + join(package_dir, "package.json"), + JSON.stringify({ + name: "test", + version: "0.0.0", + dependencies: { + "react": "my-custom-tag", + }, + }), + ); + + Bun.spawnSync({ + cmd: [bunExe(), "install", "--force"], + env: bunEnv, + cwd: package_dir, + stdout: "ignore", + stderr: "ignore", + stdin: "ignore", + }); + + await sleep(10); + + server.stop(true); + expect(urls.length).toBeGreaterThan(0); + expect(urls[0]).toBe(`http://${hostname}:${port}/prefixed-route/react`); + rmSync(package_dir, { recursive: true, force: true }); +});