Relative links in a bounty description all resolve to github.com/MergeFi/frontend, whatever repository the issue came from (incomplete fix for #651)

Aperta Adatta ai principianti
#841 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
next.js, react, typescript
Ambito
frontend, web-dev

Direzione di ricerca

Inizia da src/components/bounty/BountyDescription.tsx e dalla chiamata a BountyDescription in src/app/issues/[id]/page.tsx; segui il percorso del contesto del repository del bounty fino alla risoluzione dei link. Aggiungi o aggiorna BountyDescription.test.tsx per ./, ../, / e i link relativi semplici, usando un repository diverso da MergeFi/frontend. Il lavoro è concluso quando questi link vengono risolti nel repository e nella ref corretti, mentre i link assoluti e le ancore restano invariati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Location

src/components/bounty/BountyDescription.tsx:9-23 — the REPO_BASE_URL constant and resolveRepoUrl(), used by the a override at :33-42.

Problem

const REPO_BASE_URL = "https://github.com/MergeFi/frontend";

function resolveRepoUrl(href: string | undefined): string | undefined {
  if (!href) return href;
  if (/^[a-z][a-z0-9+.-]*:/i.test(href)) return href;
  if (href.startsWith("#")) return href;
  if (href.startsWith("./") || href.startsWith("../") || href.startsWith("/")) {
    return `${REPO_BASE_URL}/${href.replace(/^\.\//, "")}`;
  }
  return `${REPO_BASE_URL}/${href}`;
}

The base URL is a hardcoded constant pointing at MergeFi's own frontend repository. But the markdown being rendered is an arbitrary third party's GitHub issue body: src/app/issues/[id]/page.tsx:123 calls <BountyDescription description={bounty.description} />, and a Bounty can come from any org/repo on the platform. So a relative link in, say, stellar/soroban-examples' issue body is rewritten to https://github.com/MergeFi/frontend/CONTRIBUTING.md — a URL in an unrelated repository, which almost always 404s and, when it does not, points the reader at the wrong project's file.

Closed issue #651 reported that relative links "resolve against MergeFi instead of the repository". This fix changed which MergeFi URL they resolve against; it did not make them resolve against the repository. The component does not receive org or repo at all, so it has no way to build the right base.

Three further defects in the same function:

  1. Double slash on root-relative links. href = "/docs/x.md" takes the third branch, which strips only a leading ./, producing https://github.com/MergeFi/frontend//docs/x.md.
  2. No blob/tree path segment. GitHub does not serve repository files at https://github.com/<org>/<repo>/<path>; a file link needs /blob/<ref>/<path> and a directory needs /tree/<ref>/<path>. Even with the correct org/repo, .../CONTRIBUTING.md resolves to a non-existent page rather than the file.
  3. ../ is not normalised. href = "../../README.md" is concatenated literally, giving https://github.com/MergeFi/frontend/../../README.md.

The docblock at :4-8 also still describes the pre-fix behaviour ("resolve against the MergeFi/frontend repo instead of the site origin") as the bug, which reads as if the current constant were the fix.

Why it matters

GitHub issue bodies lean on relative links constantly — see ./docs/architecture.md, follow ../CONTRIBUTING.md, as in /src/lib/escrow.rs. A contributor reading a bounty on MergeFi clicks one of these to understand the task and lands on a 404 inside MergeFi's own frontend repository, with no indication that the link was rewritten. For a platform whose whole value is routing contributors to work they can do, silently misdirecting the links that explain the work is a direct obstacle; and pointing outside visitors at MergeFi's repo for another project's docs is actively confusing.

Reproduction

  1. Create or mock a bounty whose org/repo is not MergeFi/frontend — for example stellar/soroban-examples — with a description containing:
    See ./docs/setup.md, ../CONTRIBUTING.md and /src/lib.rs for context.
    
  2. Open /issues/<that bounty id>.
  3. Inspect the three rendered links. Their hrefs are:
    • https://github.com/MergeFi/frontend/docs/setup.md
    • https://github.com/MergeFi/frontend/../CONTRIBUTING.md
    • https://github.com/MergeFi/frontend//src/lib.rs
  4. Click any of them: GitHub returns 404, in the wrong repository.

Suggested fix

  1. Give BountyDescription the context it needs — add required org and repo props (and an optional defaultBranch, falling back to HEAD), and pass bounty.org / bounty.repo from src/app/issues/[id]/page.tsx:123.
  2. Build the base per render as https://github.com/${org}/${repo} and resolve the href with the URL constructor against .../blob/${ref}/ so ../ and /-prefixed paths are normalised by the platform instead of by string concatenation. Keep the existing early returns for absolute URLs and anchors.
  3. Treat a root-relative /path as repo-root-relative (/blob/<ref>/path), which is what GitHub's own markdown renderer does inside an issue body.
  4. Update the docblock at :4-8 to describe the new behaviour, and add tests in BountyDescription.test.tsx for ./, ../, / and bare relative hrefs, asserting the generated URL for a non-MergeFi org/repo.
Lingua principale
TypeScript
Stelle
1
Fork
94
Merge medio
1h 2m
PR unite (30g)
25

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di MergeFi/frontend

Tutte le issue di MergeFi/frontend

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.