aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Ai Hoshino <ambiguous404@gmail.com> 2023-09-18 19:32:02 +0800
committerGravatar GitHub <noreply@github.com> 2023-09-18 04:32:02 -0700
commitbab9889601eb13c01ebadb1f47752298259700b6 (patch)
tree8265ebd08295f01480d6b7576ceec6cb62e35fc6
parentb27b04690b8746c4cd9aa0d066a7901a5bdf7e82 (diff)
downloadbun-bab9889601eb13c01ebadb1f47752298259700b6.tar.gz
bun-bab9889601eb13c01ebadb1f47752298259700b6.tar.zst
bun-bab9889601eb13c01ebadb1f47752298259700b6.zip
fix(config): support for registry url without trailing slash (#5662)
* fix(config): support for registry URLs without trailing slash Close: #4589, #5368 * Update src/bunfig.zig * Update src/bunfig.zig --------- Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
-rw-r--r--src/bunfig.zig16
-rw-r--r--test/cli/install/bun-install.test.ts10
2 files changed, 18 insertions, 8 deletions
diff --git a/src/bunfig.zig b/src/bunfig.zig
index 76f33cb82..bb52e3053 100644
--- a/src/bunfig.zig
+++ b/src/bunfig.zig
@@ -64,19 +64,27 @@ pub const Bunfig = struct {
// Token
if (url.username.len == 0 and url.password.len > 0) {
registry.token = url.password;
- registry.url = try std.fmt.allocPrint(this.allocator, "{s}://{s}/{s}", .{ url.displayProtocol(), url.displayHostname(), std.mem.trimLeft(u8, url.pathname, "/") });
+ registry.url = try std.fmt.allocPrint(this.allocator, "{s}://{s}/{s}/", .{ url.displayProtocol(), url.displayHostname(), std.mem.trim(u8, url.pathname, "/") });
} else if (url.username.len > 0 and url.password.len > 0) {
registry.username = url.username;
registry.password = url.password;
- registry.url = try std.fmt.allocPrint(this.allocator, "{s}://{s}/{s}", .{ url.displayProtocol(), url.displayHostname(), std.mem.trimLeft(u8, url.pathname, "/") });
+ registry.url = try std.fmt.allocPrint(this.allocator, "{s}://{s}/{s}/", .{ url.displayProtocol(), url.displayHostname(), std.mem.trim(u8, url.pathname, "/") });
} else {
- registry.url = url.href;
+ if (strings.hasSuffixComptime(url.href, "/")) {
+ registry.url = url.href;
+ } else {
+ registry.url = try std.fmt.allocPrint(this.allocator, "{s}/", .{url.href});
+ }
}
},
.e_object => |obj| {
if (obj.get("url")) |url| {
try this.expect(url, .e_string);
- registry.url = url.data.e_string.data;
+ if (strings.hasSuffixComptime(url.data.e_string.data, "/")) {
+ registry.url = url.data.e_string.data;
+ } else {
+ registry.url = try std.fmt.allocPrint(this.allocator, "{s}/", .{url.data.e_string.data});
+ }
}
if (obj.get("username")) |username| {
diff --git a/test/cli/install/bun-install.test.ts b/test/cli/install/bun-install.test.ts
index 09da0bbd4..c4accb1b4 100644
--- a/test/cli/install/bun-install.test.ts
+++ b/test/cli/install/bun-install.test.ts
@@ -6018,16 +6018,17 @@ describe("Registry URLs", () => {
["example", true],
["https://example.com:demo", true],
["http://[www.example.com]/", true],
- ["c:", true],
["c:a", true],
["https://registry.npmjs.org/", false],
["https://artifactory.xxx.yyy/artifactory/api/npm/my-npm/", false], // https://github.com/oven-sh/bun/issues/3899
- ["", false],
+ ["https://artifactory.xxx.yyy/artifactory/api/npm/my-npm", false], // https://github.com/oven-sh/bun/issues/5368
+ ["", true],
["https:example.org", false],
["https://////example.com///", false],
["https://example.com/https:example.org", false],
["https://example.com/[]?[]#[]", false],
["https://example/%?%#%", false],
+ ["c:", false],
["c:/", false],
["https://點看", false], // gets converted to punycode
["https://xn--c1yn36f/", false],
@@ -6066,7 +6067,8 @@ describe("Registry URLs", () => {
const err = await new Response(stderr).text();
if (fails) {
- expect(err.includes(`Failed to join registry \"${regURL}\" and package \"notapackage\" URLs`)).toBeTrue();
+ const url = regURL.at(-1) === "/" ? regURL : regURL + "/";
+ expect(err.includes(`Failed to join registry \"${url}\" and package \"notapackage\" URLs`)).toBeTrue();
expect(err.includes("error: InvalidURL")).toBeTrue();
} else {
expect(err.includes("error: notapackage@0.0.2 failed to resolve")).toBeTrue();
@@ -6106,7 +6108,7 @@ describe("Registry URLs", () => {
expect(stderr).toBeDefined();
const err = await new Response(stderr).text();
- expect(err.includes(`Failed to join registry \"${regURL}\" and package \"notapackage\" URLs`)).toBeTrue();
+ expect(err.includes(`Failed to join registry \"${regURL}/\" and package \"notapackage\" URLs`)).toBeTrue();
expect(err.includes("warn: InvalidURL")).toBeTrue();
expect(await exited).toBe(0);