Skip to content

Commit 53e8e3d

Browse files
authored
fix(core/xref) : preserve filename in URL (#4788)
1 parent 39079f3 commit 53e8e3d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/core/xref.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,10 @@ function addDataCite(elem, query, result, conf) {
400400
// but sometimes we get lucky and we get an absolute URL from xref
401401
// which we can then use in other places (e.g., data-cite.js)
402402
const url = new URL(uri, "https://partial");
403-
const { pathname: citePath } = url;
403+
let { pathname: citePath } = url;
404+
// final resolution will be against the URL of the spec, which may end with
405+
// a filename. That filename must be preserved if there's no specific path.
406+
if (citePath === "/") citePath = "";
404407
const citeFrag = url.hash.slice(1);
405408
const dataset = { cite, citePath, citeFrag, type };
406409
if (forContext) dataset.linkFor = forContext[0];

tests/spec/core/xref-spec.js

+12
Original file line numberDiff line numberDiff line change
@@ -1043,4 +1043,16 @@ describe("Core — xref", () => {
10431043
const test2 = doc.getElementById("test2");
10441044
expect(test2.classList).toContain("respec-offending-element");
10451045
});
1046+
1047+
it("preserves the filename in the URL of an external term", async () => {
1048+
const body = `<section id="test">
1049+
<p data-cite="network-reporting">[=endpoint group=]</p>
1050+
</section>`;
1051+
const ops = makeStandardOps(null, body);
1052+
const doc = await makeRSDoc(ops);
1053+
const [specLink] = doc.querySelectorAll("#test a");
1054+
expect(specLink.href).toBe(
1055+
"https://w3c.github.io/reporting/network-reporting.html#endpoint-group"
1056+
);
1057+
});
10461058
});

0 commit comments

Comments
 (0)