From 5847274c538eda3e5556ad6dcf2cf634dbf21eed Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Thu, 23 Mar 2023 06:49:42 -0700 Subject: [PATCH] Fixes #2462 (#2463) --- src/install/install.zig | 4 +- ...un-install-pathname-trailing-slash.test.ts | 58 +++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 test/cli/install/bun-install-pathname-trailing-slash.test.ts diff --git a/src/install/install.zig b/src/install/install.zig index b8509f50ae221..91674b95d5879 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 0000000000000..8cc34fe592841 --- /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 }); +});