Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions apps/cursor/src/lib/github-plugin/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,25 @@ export async function fetchWithRateLimit(
*/
export type FetchOptions = { maxWaitMs?: number };

/**
* Raw-content URL for a repo path. Tree paths arrive unencoded, so a `#`
* would start a URL fragment, a `?` a query, and a `%` a broken escape; each
* segment is encoded while the `/` between them is kept.
*/
function rawGitHubUrl(owner: string, repo: string, path: string): string {
const encodedPath = path
.split("/")
.map((segment) => encodeURIComponent(segment))
.join("/");
return `https://raw.githubusercontent.com/${owner}/${repo}/HEAD/${encodedPath}`;
}

async function fetchGitHubFile(
owner: string,
repo: string,
path: string,
): Promise<string | null> {
const url = `https://raw.githubusercontent.com/${owner}/${repo}/HEAD/${path}`;
const url = rawGitHubUrl(owner, repo, path);
try {
const res = await fetch(url, { cache: "no-store" });
if (!res.ok) return null;
Expand Down Expand Up @@ -593,7 +606,7 @@ export async function parseGitHubPlugin(
logo = manifest.logo;
}
} catch {
logo = `https://raw.githubusercontent.com/${owner}/${repo}/HEAD/${manifest.logo.replace(/^\.?\//, "")}`;
logo = rawGitHubUrl(owner, repo, manifest.logo.replace(/^\.?\//, ""));
}
}

Expand Down