Skip to content

Commit 2a0af00

Browse files
committed
fix: strip userinfo from git repos, render explicit error for empty manifest
- Normalize git+ssh://git@github.com/... to https://github.com/... so the git@ userinfo no longer leaks into the repo link - Replace the bare return null for a nameless manifest with an explicit error alert and retry button
1 parent 35663c6 commit 2a0af00

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

apps/web/app/lib/registry/parse.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe("repoUrl", () => {
9595
it("规范化常见仓库地址", () => {
9696
expect(repoUrl("git+https://github.com/foo/bar.git")).toBe("https://github.com/foo/bar");
9797
expect(repoUrl("git+ssh://git@github.com/foo/bar.git")).toBe(
98-
"https://git@github.com/foo/bar",
98+
"https://github.com/foo/bar",
9999
);
100100
expect(repoUrl("git://github.com/foo/bar.git")).toBe("https://github.com/foo/bar");
101101
expect(repoUrl({ url: "https://github.com/foo/bar" })).toBe(

apps/web/app/lib/registry/parse.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ export function repoUrl(repository: RegistryManifest["repository"]) {
1212
if (!repository) return undefined;
1313
const url = typeof repository === "string" ? repository : repository.url;
1414
if (!url) return undefined;
15-
if (/^git(\+ssh)?:\/\//.test(url)) {
16-
return url.replace(/^git(\+ssh)?:\/\//, "https://").replace(/\.git$/, "");
17-
}
18-
if (/^git\+https?:\/\//.test(url)) {
19-
return url.replace(/^git\+https?:\/\//, "https://").replace(/\.git$/, "");
15+
if (/^git(\+ssh|\+https?)?:\/\//.test(url)) {
16+
const rest = url.replace(/^git(\+ssh|\+https?)?:\/\//, "").replace(/^[^@]+@/, "");
17+
return `https://${rest}`.replace(/\.git$/, "");
2018
}
2119
if (/^git@github\.com:(.+)$/.test(url)) {
2220
return `https://github.com/${url.replace(/^git@github\.com:/, "").replace(/\.git$/, "")}`;

apps/web/app/routes/cnpm.pkg.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,22 @@ function CnpmPkgInner({ rest }: { rest?: string }) {
9898
);
9999
}
100100

101-
if (!manifest?.name) return null;
101+
if (!manifest?.name) {
102+
return (
103+
<Layout>
104+
<PageContainer className="py-6">
105+
<Alert variant="destructive">
106+
<AlertDescription className="flex items-center justify-between gap-3">
107+
未能读取到 {name} 的包信息
108+
<Button type="button" variant="outline" size="sm" onClick={retry}>
109+
重试
110+
</Button>
111+
</AlertDescription>
112+
</Alert>
113+
</PageContainer>
114+
</Layout>
115+
);
116+
}
102117

103118
const requestedVersion = params.get("version") || "";
104119
const fallbackVersion = sortVersions(manifest.versions)[0]?.version;

0 commit comments

Comments
 (0)