Skip to content

Commit 82f0793

Browse files
committed
fix: escape the item path in listing field links
1 parent f106420 commit 82f0793

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

‎src/project/types/website/listing/website-listing-template.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ export function reshapeListing(
421421
const value = val || item[field] || " ";
422422
const path = item.path;
423423
if (path && value !== undefined && fieldLinks.includes(field)) {
424-
return `<a href="${path}"${targetAttrs(item)} class="${field}${
424+
return `<a href="${encodeAttributeValue(path)}"${targetAttrs(item)} class="${field}${
425425
clz ? ` ${clz}` : ""
426426
}">${value}</a>`;
427427
} else {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: "Link target - hostile path"
3+
listing:
4+
id: hostile-path-listing
5+
type: table
6+
contents:
7+
- path: 'https://example.com/" onmouseover="x'
8+
title: "Item A"
9+
target: _blank
10+
fields: [title]
11+
---
12+
13+
::: {#hostile-path-listing}
14+
:::

‎tests/integration/playwright/tests/html-listing-link-target.spec.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@ test.describe("Hostile target value", () => {
158158
expect(await link.getAttribute("target")).toBe('_blank" onmouseover="x');
159159
expect(await link.getAttribute("onmouseover")).toBeNull();
160160
});
161+
162+
test("hostile path stays one attribute in table links", async ({ page: browserPage }) => {
163+
await browserPage.goto(`${base}/hostile-path.html`);
164+
await browserPage.waitForSelector(".quarto-listing-table");
165+
166+
const link = browserPage.locator(".quarto-listing-table a.title").first();
167+
expect(await link.getAttribute("href")).toContain("onmouseover");
168+
expect(await link.getAttribute("onmouseover")).toBeNull();
169+
});
161170
});
162171

163172
test.describe("Description after listing updates", () => {

0 commit comments

Comments
 (0)