theme: fix snyk code issues #633

This commit is contained in:
Sören Weber 2023-08-31 12:34:23 +02:00
parent 82d3a9aabf
commit e6b50128e4
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
2 changed files with 8 additions and 2 deletions

View file

@ -158,7 +158,8 @@ function initLunrJs() {
function search(term) {
// Find the item in our index corresponding to the Lunr one to have more info
// Remove Lunr special search characters: https://lunrjs.com/guides/searching.html
var searchTerm = lunr.tokenizer(term.replace(/[*:^~+-]/, ' ')).reduce( function(a,token){return a.concat(searchPatterns(token.str))}, []).join(' ');
term = term.replace( /[*:^~+-]/g, ' ' );
var searchTerm = lunr.tokenizer( term ).reduce( function(a,token){return a.concat(searchPatterns(token.str))}, []).join(' ');
return !searchTerm || !lunrIndex ? [] : lunrIndex.search(searchTerm).map(function(result) {
return { index: result.ref, matches: Object.keys(result.matchData.metadata) }
});

View file

@ -37,6 +37,10 @@ var psm;
var pst;
var elc = document.querySelector('#body-inner');
function regexEscape( s ){
return s.replace( /[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&' );
}
function documentFocus(){
elc.focus();
psc && psc.scrollbarY.focus();
@ -1082,6 +1086,7 @@ function scrollToPositions() {
var search = sessionStorage.getItem( baseUriFull+'search-value' );
if( search && search.length ){
search = regexEscape( search );
var found = elementContains( search, elc );
var searchedElem = found.length && found[ 0 ];
if( searchedElem ){
@ -1169,7 +1174,7 @@ function highlight( es, words, options ){
return word != '';
});
words = words.map( function( word, i ){
return word.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
return regexEscape( word );
});
if( words.length == 0 ){ return this; }