diff --git a/goon/browserassets/js/browserOutput.js b/goon/browserassets/js/browserOutput.js
index 3c266fc023e..d20d2eb239e 100644
--- a/goon/browserassets/js/browserOutput.js
+++ b/goon/browserassets/js/browserOutput.js
@@ -174,51 +174,51 @@ function setHighlightColor() {
}
}
-function escapeRegex(input){ // put this in a function incase it ever needs to be used elsewhere, makes code cleaner
+function escapeRegexCharacters(input){ //escapes any characters that could be interpreted as regex patterns, potentially causing patterns to break if not escaped
return input.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
//Highlights words based on user settings
function highlightTerms(el) {
- if(regexHasError) return; //just stop right there ig the regex is gonna except
+ if (regexHasError) return; //just stop right there ig the regex is gonna except
function highlightRecursor(element,term){ //recursor function to do the highlighting proper
- var regex = new RegExp("("+term+")","gi")
+ var regex = new RegExp(term,"gi");
function replace(str) {
- return str.replace(regex,'$&')
+ return str.replace(regex,'$&');
}
- var s=''
- var work=element.innerHTML;
- var ind=0;
+ var s = '';
+ var work = element.innerHTML;
+ var ind = 0;
while(ind < work.length) {
- var next_term=work.substring(ind).search(regex);
- if(next_term!=-1)next_term+=ind;
- var next_tag =work.indexOf('<',ind)
+ var next_term = work.substring(ind).search(regex);
+ if(next_term != -1) next_term += ind;
+ var next_tag = work.indexOf('<',ind);
if(next_tag == -1) {
s+=replace(work.substring(ind));
break;
}
else if(next_term==-1) {
- s+=work.substring(ind)
+ s += work.substring(ind);
break;
}
else if(next_tag < next_term) {
- var temp=work.indexOf('>',next_tag)
- s+=work.substring(ind,temp+1);
- ind=temp+1;
+ var temp = work.indexOf('>',next_tag);
+ s += work.substring(ind,temp+1);
+ ind = temp+1;
}
else {
- s+=replace(work.substring(ind,next_tag));
- ind=next_tag
+ s += replace(work.substring(ind,next_tag));
+ ind = next_tag;
}
}
- element.innerHTML=s;
+ element.innerHTML = s;
}
for (var i = 0; i < opts.highlightTerms.length; i++) { //Each highlight term
@@ -226,18 +226,18 @@ function highlightTerms(el) {
if(!opts.highlightRegexEnable){
var innerTerms = opts.highlightTerms[i].split(" ")
for(var a in innerTerms){
- highlightRecursor(el,escapeRegex(innerTerms[a]))
+ highlightRecursor(el, escapeRegexCharacters(innerTerms[a]))
}
}
else {
try{
- new RegExp(opts.highlightTerms[i],"gmi") // check to make sure the pattern wont cause issues
+ new RegExp(opts.highlightTerms[i],"gmi"); // check to make sure the pattern wont cause issues
} catch(e){
- el.innerHTML+='
Your highlight regex pattern - '+opts.highlightTerms[i]+' - is malformed.
Your highlights have been disabled until they are next edited
Thrown exception: '+e+''
+ el.innerHTML += '
Your highlight regex pattern - '+opts.highlightTerms[i]+' - is malformed.
Your highlights have been disabled until they are next edited
Thrown exception: '+e+'';
regexHasError = true;
return;
}
- highlightRecursor(el,opts.highlightTerms[i])
+ highlightRecursor(el, opts.highlightTerms[i]);
}
}
}