@@ -35,6 +35,20 @@ <h1 class="search-results-title"></h1>
3535
3636 <!-- localized behavior: detect lang, apply messages, append lang to links -->
3737 < script >
38+ function escapeHTML ( str ) {
39+ if ( ! str ) return '' ;
40+ return str . replace ( / [ & < > " ' ] / g, function ( m ) {
41+ switch ( m ) {
42+ case '&' : return '&' ;
43+ case '<' : return '<' ;
44+ case '>' : return '>' ;
45+ case '"' : return '"' ;
46+ case "'" : return ''' ;
47+ default : return m ;
48+ }
49+ } ) ;
50+ }
51+
3852 function getQueryParam ( name ) {
3953 const params = new URLSearchParams ( window . location . search ) ;
4054 return params . get ( name ) ;
@@ -56,8 +70,8 @@ <h1 class="search-results-title"></h1>
5670 loading : 'Loading search index...' ,
5771 index_empty : 'Warning: Search index is empty or could not be loaded.' ,
5872 no_query : 'No search term provided.' ,
59- found_results : ( n , q ) => `Found ${ n } results for <strong>${ q } </strong>:` ,
60- no_results_for : q => `No results found for <strong>${ q } </strong>.` ,
73+ found_results : ( n , q ) => `Found ${ n } results for <strong>${ escapeHTML ( q ) } </strong>:` ,
74+ no_results_for : q => `No results found for <strong>${ escapeHTML ( q ) } </strong>.` ,
6175 popular_topics : 'Popular topics:' ,
6276 home_aria : 'Back to help homepage'
6377 } ,
@@ -66,8 +80,8 @@ <h1 class="search-results-title"></h1>
6680 loading : "Chargement de l'index de recherche..." ,
6781 index_empty : "Attention : l'index de recherche est vide ou n'a pas pu être chargé." ,
6882 no_query : "Aucun terme de recherche fourni." ,
69- found_results : ( n , q ) => `Trouvé ${ n } résultat(s) pour <strong>${ q } </strong> :` ,
70- no_results_for : q => `Aucun résultat pour <strong>${ q } </strong>.` ,
83+ found_results : ( n , q ) => `Trouvé ${ n } résultat(s) pour <strong>${ escapeHTML ( q ) } </strong> :` ,
84+ no_results_for : q => `Aucun résultat pour <strong>${ escapeHTML ( q ) } </strong>.` ,
7185 popular_topics : 'Sujets populaires :' ,
7286 home_aria : "Retour à la page d'accueil de l'aide"
7387 }
@@ -211,7 +225,7 @@ <h1 class="search-results-title"></h1>
211225 if ( helpIndex . length === 0 ) {
212226 resultsDiv . innerHTML = `<p>${ msg . index_empty } </p>` ;
213227 if ( query ) {
214- resultsDiv . innerHTML += `<p>${ msg . no_results_for ( query ) } </p>` ;
228+ resultsDiv . innerHTML += `<p>${ msg . no_results_for ( escapeHTML ( query ) ) } </p>` ;
215229 }
216230 return ;
217231 }
@@ -226,13 +240,16 @@ <h1 class="search-results-title"></h1>
226240
227241 results . forEach ( result => {
228242 const href = appendLangToUrl ( result . url || result . path || './homepage.html' ) ;
229- html += `
230- <div class="result-item">
231- <h3><a href="${ href } " target="contentFrame">${ result . title } </a></h3>
232- <p>${ result . snippet } </p>
233- <small>${ result . path || '' } </small>
234- </div>
235- ` ;
243+ const safeTitle = escapeHTML ( result . title || '' ) ;
244+ const safeSnippet = escapeHTML ( result . snippet || '' ) ;
245+ const safePath = escapeHTML ( result . path || '' ) ;
246+ html += `
247+ <div class="result-item">
248+ <h3><a href="${ href } " target="contentFrame">${ safeTitle } </a></h3>
249+ <p>${ safeSnippet } </p>
250+ <small>${ safePath } </small>
251+ </div>
252+ ` ;
236253 } ) ;
237254
238255 resultsDiv . innerHTML = html ;
@@ -245,17 +262,18 @@ <h3><a href="${href}" target="contentFrame">${result.title}</a></h3>
245262 let html = `<p>${ msg . popular_topics } </p>` ;
246263 topResults . forEach ( result => {
247264 const href = appendLangToUrl ( result . url || result . path || './homepage.html' ) ;
248- html += `
249- <div class="result-item">
250- <h3><a href="${ href } " target="contentFrame">${ result . title } </a></h3>
251- </div>
252- ` ;
253- } ) ;
265+ const safeTitle = escapeHTML ( result . title || '' ) ;
266+ html += `
267+ <div class="result-item">
268+ <h3><a href="${ href } " target="contentFrame">${ safeTitle } </a></h3>
269+ </div>
270+ ` ;
271+ } ) ;
254272 resultsDiv . innerHTML += html ;
255273 }
256274 }
257275 } catch ( error ) {
258- resultsDiv . innerHTML = `<p>Error loading search index: ${ error && error . message ? error . message : error } </p>` ;
276+ resultsDiv . innerHTML = `<p>Error loading search index: ${ escapeHTML ( error && error . message ? error . message : error ) } </p>` ;
259277 }
260278 }
261279
0 commit comments