From a717e2e81a9698e200d625fca48091f8ea5696a4 Mon Sep 17 00:00:00 2001 From: zurdi Date: Tue, 22 Sep 2026 20:15:00 +0200 Subject: [PATCH] fix(v2): keep the changelog's link rewrite out of code and queries Addresses Greptile's review of #4705. The rewrite matched a reference anywhere but right after a link's bracket, so one written inside code was turned into markdown the preview then printed verbatim, and one inside a longer link label nested a link in a link. Code spans, fenced blocks and whole existing links are now matched first and handed back untouched. A trailing query no longer splits a reference either: `?` joins the guard that already kept `/files` and `#issuecomment-1` whole. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_016bZ7R3xC73MZu1vTNuatPK --- frontend/src/v2/utils/githubLinks.test.ts | 20 +++++++++++++++++++- frontend/src/v2/utils/githubLinks.ts | 14 ++++++++------ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/frontend/src/v2/utils/githubLinks.test.ts b/frontend/src/v2/utils/githubLinks.test.ts index 83a79a6e4..855d42dc5 100644 --- a/frontend/src/v2/utils/githubLinks.test.ts +++ b/frontend/src/v2/utils/githubLinks.test.ts @@ -43,7 +43,24 @@ describe("shortenGithubLinks", () => { // Rewriting these would nest a link inside a link. it("leaves a reference that is already a link alone", () => { - const notes = [`[the fix](${PR})`, `[${PR}](${PR})`, `<${PR}>`].join("\n"); + const notes = [ + `[the fix](${PR})`, + `[${PR}](${PR})`, + `[see ${PR} for the details](${PR})`, + `<${PR}>`, + ].join("\n"); + + expect(shortenGithubLinks(notes, REPO)).toBe(notes); + }); + + // Code reads as written, so a rewrite would show the markdown itself. + it("leaves a reference inside code alone", () => { + const notes = [ + `Compare it with \`${PR}\`:`, + "```sh", + `curl ${PR}`, + "```", + ].join("\n"); expect(shortenGithubLinks(notes, REPO)).toBe(notes); }); @@ -52,6 +69,7 @@ describe("shortenGithubLinks", () => { const notes = [ `${PR}/files`, `${PR}#issuecomment-1`, + `${PR}?diff=split`, "https://github.com/rommapp/romm/compare/5.0.0...5.1.0", ].join("\n"); diff --git a/frontend/src/v2/utils/githubLinks.ts b/frontend/src/v2/utils/githubLinks.ts index a246b2947..f01623098 100644 --- a/frontend/src/v2/utils/githubLinks.ts +++ b/frontend/src/v2/utils/githubLinks.ts @@ -1,7 +1,8 @@ -// A bare pull request or issue URL, not one already inside a markdown link -// (as its text or its target) or an ``, and not a deeper page of it. -const REFERENCE_URL = - /(?\s]*>)|https:\/\/github\.com\/([\w.-]+\/[\w.-]+)\/(?:pull|issues)\/(\d+)(?![\w/#?])/g; /** * Rewrites bare pull request and issue URLs in `markdown` the way GitHub @@ -13,8 +14,9 @@ const REFERENCE_URL = */ export function shortenGithubLinks(markdown: string, repo: string): string { return markdown.replace( - REFERENCE_URL, - (url, target: string, number: string) => { + VERBATIM_OR_REFERENCE, + (url, verbatim: string | undefined, target: string, number: string) => { + if (verbatim !== undefined) return verbatim; const prefix = target.toLowerCase() === repo.toLowerCase() ? "" : target; return `[${prefix}#${number}](${url})`; },