aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-03-23 06:49:42 -0700
committerGravatar GitHub <noreply@github.com> 2023-03-23 15:49:42 +0200
commit52d27659a2b28cd39c139aadc1fa2a64695405fc (patch)
tree10c912c270f3b514d399887d5bad8e49fbb4a73f
parent732c5e7fa9b0bb89938ca001749a13501386485e (diff)
downloadbun-52d27659a2b28cd39c139aadc1fa2a64695405fc.tar.gz
bun-52d27659a2b28cd39c139aadc1fa2a64695405fc.tar.zst
bun-52d27659a2b28cd39c139aadc1fa2a64695405fc.zip
Fixes #2462 (#2463)
-rw-r--r--src/install/install.zig4
-rw-r--r--test/cli/install/bun-install-pathname-trailing-slash.test.ts58
2 files changed, 60 insertions, 2 deletions
diff --git a/src/install/install.zig b/src/install/install.zig
index b8509f50a..91674b95d 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 000000000..8cc34fe59
--- /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 });
+});