Skip to content

Commit 89e2829

Browse files
Fix HTML dataset unescape
1 parent 6407f5e commit 89e2829

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

Public/js/lookup_view.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,21 @@ export class LookupView {
7272
)
7373
)
7474
.map((item) => {
75+
const title = escapeHTML(item.title);
76+
const type = escapeHTML(item.type);
77+
const content = escapeHTML(item.content);
7578
if (item.range) {
7679
const range = JSON.parse(item.range);
7780
const sourceRange = `${range.startRow}:${range.startColumn} - ${range.endRow}:${range.endColumn}`;
7881
return `<dt class="text-truncate" style="max-width: calc(40vw - 20px);">
79-
<span class="badge annotation" style="width: auto; text-align: start;">Text</span><span class="font-monospace">${item.title}</span>
82+
<span class="badge annotation" style="width: auto; text-align: start;">Text</span><span class="font-monospace">${title}</span>
8083
</dt>
81-
<dd><div><span class="badge annotation">Range</span>${sourceRange}</div><div><span class="badge annotation">${item.type}</span>${item.content}</div></dd>`;
84+
<dd><div><span class="badge annotation">Range</span>${sourceRange}</div><div><span class="badge annotation">${type}</span>${content}</div></dd>`;
8285
} else {
8386
return `<dt class="text-truncate" style="max-width: calc(40vw - 20px);">
84-
<span class="badge annotation" style="width: auto; text-align: start;">Text</span><span class="font-monospace">${item.title}</span>
87+
<span class="badge annotation" style="width: auto; text-align: start;">Text</span><span class="font-monospace">${title}</span>
8588
</dt>
86-
<dd><div><span class="badge annotation">${item.type}</span>${item.content}</div></dd>`;
89+
<dd><div><span class="badge annotation">${type}</span>${content}</div></dd>`;
8790
}
8891
})
8992
.join("");
@@ -134,3 +137,9 @@ function createDOMRectElement(domRect) {
134137
rectElement.style.backgroundColor = "rgba(81, 101, 255, 0.25)";
135138
document.body.appendChild(rectElement);
136139
}
140+
141+
function escapeHTML(text) {
142+
const div = document.createElement("div");
143+
div.appendChild(document.createTextNode(text));
144+
return div.innerHTML;
145+
}

0 commit comments

Comments
 (0)