@@ -324,6 +324,14 @@ const Search = {
324
324
const titles = Search . _index . titles ;
325
325
const allTitles = Search . _index . alltitles ;
326
326
const indexEntries = Search . _index . indexentries ;
327
+ const htmlEscape = ( text ) => {
328
+ return String ( text )
329
+ . replaceAll ( "&" , "&" )
330
+ . replaceAll ( "<" , "<" )
331
+ . replaceAll ( ">" , ">" )
332
+ . replaceAll ( '"' , """ )
333
+ . replaceAll ( "'" , "'" ) ;
334
+ }
327
335
328
336
// Collect multiple result groups to be sorted separately and then ordered.
329
337
// Each is an array of [docname, title, anchor, descr, score, filename, kind].
@@ -340,7 +348,9 @@ const Search = {
340
348
const boost = titles [ file ] === title ? 1 : 0 ; // add a boost for document titles
341
349
normalResults . push ( [
342
350
docNames [ file ] ,
343
- titles [ file ] !== title ? `${ titles [ file ] } > ${ title } ` : title ,
351
+ htmlEscape (
352
+ titles [ file ] !== title ? `${ titles [ file ] } > ${ title } ` : title
353
+ ) ,
344
354
id !== null ? "#" + id : "" ,
345
355
null ,
346
356
score + boost ,
@@ -358,7 +368,7 @@ const Search = {
358
368
const score = Math . round ( 100 * queryLower . length / entry . length ) ;
359
369
const result = [
360
370
docNames [ file ] ,
361
- titles [ file ] ,
371
+ htmlEscape ( titles [ file ] ) ,
362
372
id ? "#" + id : "" ,
363
373
null ,
364
374
score ,
0 commit comments