@@ -248,7 +248,7 @@ function field(matchData, record, name) {
|
||||
if (!positions.length) return text
|
||||
|
||||
// Highlight the text
|
||||
return positions
|
||||
const highlighted = positions
|
||||
.map(([prev, start, end], i) => [
|
||||
text.slice(prev, start),
|
||||
mark(text.slice(start, end)),
|
||||
@@ -257,6 +257,16 @@ function field(matchData, record, name) {
|
||||
.flat()
|
||||
.filter(Boolean)
|
||||
.join('')
|
||||
|
||||
// We can't HTML escape the content until AFTER all the matchData positions
|
||||
// have been processed otherwise, the positions should shift.
|
||||
// The only HTML that is OK to keep is <mark> and </mark>.
|
||||
return highlighted
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/<mark>/g, '<mark>')
|
||||
.replace(/<\/mark>/g, '</mark>')
|
||||
}
|
||||
|
||||
function mark(text) {
|
||||
|
||||
Reference in New Issue
Block a user