fix(#6347): Searching a Notebook with whitelisted links for '.' exposes some html (#6396)

This commit is contained in:
Vitor Henckel 2023-03-23 18:23:49 -03:00 committed by GitHub
parent f39f8df4e2
commit 665ba6dae1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,9 +49,19 @@ export default {
},
computed: {
highlightedText() {
let regex = new RegExp(`(?<!<[^>]*)(${this.highlight})`, 'gi');
const highlight = this.highlight;
return this.text.replace(regex, `<span class="${this.highlightClass}">${this.highlight}</span>`);
const normalCharsRegex = /^[^A-Za-z0-9]+$/g;
const newHighLight = normalCharsRegex.test(highlight)
? `\\${highlight}`
: highlight;
const highlightRegex = new RegExp(`(?<!<[^>]*)(${newHighLight})`, 'gi');
const replacement = `<span class="${this.highlightClass}">${highlight}</span>`;
return this.text.replace(highlightRegex, replacement);
}
}
};