Skip to content

Commit

Permalink
fix(core/xref) : preserve filename in URL (#4788)
Browse files Browse the repository at this point in the history
  • Loading branch information
tidoust authored Sep 7, 2024
1 parent 39079f3 commit 53e8e3d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/core/xref.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,10 @@ function addDataCite(elem, query, result, conf) {
// but sometimes we get lucky and we get an absolute URL from xref
// which we can then use in other places (e.g., data-cite.js)
const url = new URL(uri, "https://partial");
const { pathname: citePath } = url;
let { pathname: citePath } = url;
// final resolution will be against the URL of the spec, which may end with
// a filename. That filename must be preserved if there's no specific path.
if (citePath === "/") citePath = "";
const citeFrag = url.hash.slice(1);
const dataset = { cite, citePath, citeFrag, type };
if (forContext) dataset.linkFor = forContext[0];
Expand Down
12 changes: 12 additions & 0 deletions tests/spec/core/xref-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1043,4 +1043,16 @@ describe("Core — xref", () => {
const test2 = doc.getElementById("test2");
expect(test2.classList).toContain("respec-offending-element");
});

it("preserves the filename in the URL of an external term", async () => {
const body = `<section id="test">
<p data-cite="network-reporting">[=endpoint group=]</p>
</section>`;
const ops = makeStandardOps(null, body);
const doc = await makeRSDoc(ops);
const [specLink] = doc.querySelectorAll("#test a");
expect(specLink.href).toBe(
"https://w3c.github.io/reporting/network-reporting.html#endpoint-group"
);
});
});

0 comments on commit 53e8e3d

Please sign in to comment.