diff options
author | 2023-10-17 14:10:25 -0700 | |
---|---|---|
committer | 2023-10-17 14:10:25 -0700 | |
commit | 7458b969c5d9971e89d187b687e1924e78da427e (patch) | |
tree | ee3dbf95c728cf407bf49a27826b541e9264a8bd /src/install/repository.zig | |
parent | d4a2c29131ec154f5e4db897d4deedab2002cbc4 (diff) | |
parent | e91436e5248d947b50f90b4a7402690be8a41f39 (diff) | |
download | bun-7458b969c5d9971e89d187b687e1924e78da427e.tar.gz bun-7458b969c5d9971e89d187b687e1924e78da427e.tar.zst bun-7458b969c5d9971e89d187b687e1924e78da427e.zip |
Merge branch 'main' into postinstall_3
Diffstat (limited to 'src/install/repository.zig')
-rw-r--r-- | src/install/repository.zig | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/install/repository.zig b/src/install/repository.zig index 564306733..17afec079 100644 --- a/src/install/repository.zig +++ b/src/install/repository.zig @@ -27,6 +27,12 @@ pub const Repository = extern struct { resolved: GitSHA = .{}, package_name: String = .{}, + pub const Hosts = bun.ComptimeStringMap(string, .{ + .{ "bitbucket", ".org" }, + .{ "github", ".com" }, + .{ "gitlab", ".com" }, + }); + pub fn verify(this: *const Repository) void { this.owner.assertDefined(); this.repo.assertDefined(); @@ -125,15 +131,31 @@ pub const Repository = extern struct { if (strings.hasPrefixComptime(url, "ssh://")) { final_path_buf[0.."https".len].* = "https".*; bun.copy(u8, final_path_buf["https".len..], url["ssh".len..]); - return final_path_buf[0..(url.len - "ssh".len + "https".len)]; + return final_path_buf[0 .. url.len - "ssh".len + "https".len]; } + if (Dependency.isSCPLikePath(url)) { final_path_buf[0.."https://".len].* = "https://".*; var rest = final_path_buf["https://".len..]; + + const colon_index = strings.indexOfChar(url, ':'); + + if (colon_index) |colon| { + // make sure known hosts have `.com` or `.org` + if (Hosts.get(url[0..colon])) |tld| { + bun.copy(u8, rest, url[0..colon]); + bun.copy(u8, rest[colon..], tld); + rest[colon + tld.len] = '/'; + bun.copy(u8, rest[colon + tld.len + 1 ..], url[colon + 1 ..]); + return final_path_buf[0 .. url.len + "https://".len + tld.len]; + } + } + bun.copy(u8, rest, url); - if (strings.indexOfChar(rest, ':')) |colon| rest[colon] = '/'; - return final_path_buf[0..(url.len + "https://".len)]; + if (colon_index) |colon| rest[colon] = '/'; + return final_path_buf[0 .. url.len + "https://".len]; } + return null; } |