Skip to content

Commit 681ee18

Browse files
committed
escape html
1 parent 62779ca commit 681ee18

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

sphinx/themes/basic/static/searchtools.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,14 @@ const Search = {
324324
const titles = Search._index.titles;
325325
const allTitles = Search._index.alltitles;
326326
const indexEntries = Search._index.indexentries;
327+
const htmlEscape = (text) => {
328+
return String(text)
329+
.replaceAll("&", "&")
330+
.replaceAll("<", "&lt;")
331+
.replaceAll(">", "&gt;")
332+
.replaceAll('"', "&quot;")
333+
.replaceAll("'", "&#39;");
334+
}
327335

328336
// Collect multiple result groups to be sorted separately and then ordered.
329337
// Each is an array of [docname, title, anchor, descr, score, filename, kind].
@@ -340,7 +348,9 @@ const Search = {
340348
const boost = titles[file] === title ? 1 : 0; // add a boost for document titles
341349
normalResults.push([
342350
docNames[file],
343-
titles[file] !== title ? `${titles[file]} > ${title}` : title,
351+
htmlEscape(
352+
titles[file] !== title ? `${titles[file]} > ${title}` : title
353+
),
344354
id !== null ? "#" + id : "",
345355
null,
346356
score + boost,
@@ -358,7 +368,7 @@ const Search = {
358368
const score = Math.round(100 * queryLower.length / entry.length);
359369
const result = [
360370
docNames[file],
361-
titles[file],
371+
htmlEscape(titles[file]),
362372
id ? "#" + id : "",
363373
null,
364374
score,

0 commit comments

Comments
 (0)