Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core/inlines): prevent creating links inside links #4786

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/core/inlines.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 5 additions & 1 deletion tests/spec/core/inlines-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
<section>
<dfn id="dfn">
Expand All @@ -639,14 +639,18 @@ describe("Core - Inlines", () => {
{{ ReferrerPolicy/"no-referrer" }}
123
</dfn>
<a id="link" href="#dfn">A link containing an IDL reference {{Window}}</a>
</section>
`;
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)");
Expand Down