From 39079f3311461334cc1b8d2f302fb69ac0ffb7e1 Mon Sep 17 00:00:00 2001 From: Dominique Hazael-Massieux Date: Thu, 5 Sep 2024 14:04:34 +0200 Subject: [PATCH] Prevent creating links from inline links inside links (#4786) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: François Daoust --- src/core/inlines.js | 4 ++-- tests/spec/core/inlines-spec.js | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core/inlines.js b/src/core/inlines.js index 71f8308b98..b6651e2b86 100644 --- a/src/core/inlines.js +++ b/src/core/inlines.js @@ -145,9 +145,9 @@ function inlineXrefMatches(matched, text) { } const node = idlStringToHtml(ref); - // If it's inside a dfn, it should just be coded, not linked. + // If it's inside a dfn or a `a`, it should just be coded, not linked. // This is because dfn elements are treated as links by ReSpec via role=link. - const renderAsCode = !!text.parentElement.closest("dfn"); + const renderAsCode = !!text.parentElement.closest("dfn,a"); return renderAsCode ? inlineCodeMatches(`\`${node.textContent}\``) : node; } diff --git a/tests/spec/core/inlines-spec.js b/tests/spec/core/inlines-spec.js index 7e26c43818..a08815174c 100644 --- a/tests/spec/core/inlines-spec.js +++ b/tests/spec/core/inlines-spec.js @@ -629,7 +629,7 @@ describe("Core - Inlines", () => { expect(primitiveData.lt).toBe("unsigned short"); }); - it("doesn't link processed inline WebIDL if inside a definition", async () => { + it("doesn't link processed inline WebIDL if inside a definition or a link", async () => { const body = `
@@ -639,14 +639,18 @@ describe("Core - Inlines", () => { {{ ReferrerPolicy/"no-referrer" }} 123 + A link containing an IDL reference {{Window}}
`; const doc = await makeRSDoc(makeStandardOps(null, body)); const dfn = doc.getElementById("dfn"); expect(dfn.querySelector("a")).toBeNull(); + const link = doc.getElementById("link"); + expect(link.querySelector("a")).toBeNull(); const codeElements = dfn.querySelectorAll("code"); expect(codeElements).toHaveSize(3); + expect(link.querySelectorAll("code")).toHaveSize(1); const [eventListen, event, noRef] = codeElements; expect(eventListen.textContent).toBe("addEventListener(type, callback)");