aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Dylan Conway <35280289+dylan-conway@users.noreply.github.com> 2023-09-22 18:41:55 -0700
committerGravatar GitHub <noreply@github.com> 2023-09-22 18:41:55 -0700
commitee93f1b88c141f1cc5d917a60ddb4a3e2706f1ff (patch)
treed493c85f4cc4d4fa5f3a32a0cd53fcf25aebc0c2
parentffd21e98e79a86b2b034bae2eea4da3ddefceeb7 (diff)
downloadbun-ee93f1b88c141f1cc5d917a60ddb4a3e2706f1ff.tar.gz
bun-ee93f1b88c141f1cc5d917a60ddb4a3e2706f1ff.tar.zst
bun-ee93f1b88c141f1cc5d917a60ddb4a3e2706f1ff.zip
[install] fix GitHub dependency bugs (#5941)
* handle branches with slashes * handle empty repo string
-rw-r--r--src/install/dependency.zig16
-rw-r--r--src/install/install.zig15
2 files changed, 21 insertions, 10 deletions
diff --git a/src/install/dependency.zig b/src/install/dependency.zig
index 3a9ee6b54..9c7bcf479 100644
--- a/src/install/dependency.zig
+++ b/src/install/dependency.zig
@@ -189,24 +189,28 @@ pub inline fn isGitHubRepoPath(dependency: string) bool {
if (dependency.len < 3) return false;
var hash_index: usize = 0;
- var slash_index: usize = 0;
+
+ // the branch could have slashes
+ // - oven-sh/bun#brach/name
+ var first_slash_index: usize = 0;
for (dependency, 0..) |c, i| {
switch (c) {
'/' => {
if (i == 0) return false;
- if (slash_index > 0) return false;
- slash_index = i;
+ if (first_slash_index == 0) {
+ first_slash_index = i;
+ }
},
'#' => {
if (i == 0) return false;
if (hash_index > 0) return false;
- if (slash_index == 0) return false;
+ if (first_slash_index == 0) return false;
hash_index = i;
},
// Not allowed in username
'.', '_' => {
- if (slash_index == 0) return false;
+ if (first_slash_index == 0) return false;
},
// Must be alphanumeric
'-', 'a'...'z', 'A'...'Z', '0'...'9' => {},
@@ -214,7 +218,7 @@ pub inline fn isGitHubRepoPath(dependency: string) bool {
}
}
- return hash_index != dependency.len - 1 and slash_index > 0 and slash_index != dependency.len - 1;
+ return hash_index != dependency.len - 1 and first_slash_index > 0 and first_slash_index != dependency.len - 1;
}
// This won't work for query string params, but I'll let someone file an issue
diff --git a/src/install/install.zig b/src/install/install.zig
index 96f6f7b3e..10eaac1f4 100644
--- a/src/install/install.zig
+++ b/src/install/install.zig
@@ -2129,14 +2129,21 @@ pub const PackageManager = struct {
github_api_domain = api_domain;
}
}
+
+ const owner = this.lockfile.str(&repository.owner);
+ const repo = this.lockfile.str(&repository.repo);
+ const committish = this.lockfile.str(&repository.committish);
+
return std.fmt.allocPrint(
this.allocator,
- "https://{s}/repos/{s}/{s}/tarball/{s}",
+ "https://{s}/repos/{s}/{s}{s}tarball/{s}",
.{
github_api_domain,
- this.lockfile.str(&repository.owner),
- this.lockfile.str(&repository.repo),
- this.lockfile.str(&repository.committish),
+ owner,
+ repo,
+ // repo might be empty if dep is https://github.com/... style
+ if (repo.len > 0) "/" else "",
+ committish,
},
) catch unreachable;
}