Skip to content

Commit 4fc2dfd

Browse files
committed
Escape HTML on display
1 parent aaa2f59 commit 4fc2dfd

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

sphinx/themes/basic/static/searchtools.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const _displayItem = (item, searchTerms, highlightTerms) => {
9999
let linkEl = listItem.appendChild(document.createElement("a"));
100100
linkEl.href = linkUrl + anchor;
101101
linkEl.dataset.score = score;
102-
linkEl.innerHTML = title;
102+
linkEl.innerHTML = _escapeHTML(title);
103103
if (descr) {
104104
listItem.appendChild(document.createElement("span")).innerHTML =
105105
" (" + descr + ")";
@@ -349,9 +349,7 @@ const Search = {
349349
const boost = titles[file] === title ? 1 : 0; // add a boost for document titles
350350
normalResults.push([
351351
docNames[file],
352-
_escapeHTML(
353-
titles[file] !== title ? `${titles[file]} > ${title}` : title
354-
),
352+
titles[file] !== title ? `${titles[file]} > ${title}` : title,
355353
id !== null ? "#" + id : "",
356354
null,
357355
score + boost,
@@ -369,7 +367,7 @@ const Search = {
369367
const score = Math.round(100 * queryLower.length / entry.length);
370368
const result = [
371369
docNames[file],
372-
_escapeHTML(titles[file]),
370+
titles[file],
373371
id ? "#" + id : "",
374372
null,
375373
score,

tests/js/searchtools.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ describe('Basic html theme search', function() {
184184

185185
expectedRanking = [
186186
['index', 'Main Page', '#index-0'], /* index entry */
187-
['index', 'Main Page > Result Scoring', '#result-scoring'], /* title */
187+
['index', 'Main Page > Result Scoring', '#result-scoring'], /* title */
188188
];
189189

190190
searchParameters = Search._parseQuery('scoring');
@@ -198,7 +198,7 @@ describe('Basic html theme search', function() {
198198

199199
expectedRanking = [
200200
['relevance', 'Relevance', ''], /* main title */
201-
['index', 'Main Page > Relevance', '#relevance'], /* subsection heading title */
201+
['index', 'Main Page > Relevance', '#relevance'], /* subsection heading title */
202202
];
203203

204204
searchParameters = Search._parseQuery('relevance');

0 commit comments

Comments
 (0)