@@ -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 ( "<" , "<" )
331+ . replaceAll ( ">" , ">" )
332+ . replaceAll ( '"' , """ )
333+ . replaceAll ( "'" , "'" ) ;
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