fix: Add escapeHtml for search (#1551)

Co-authored-by: Anix <anik220798@gmail.com>
This commit is contained in:
沈唁 2021-04-12 09:47:39 +08:00 committed by GitHub
parent 32203b77bf
commit c24f7f6f0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -178,7 +178,7 @@ export function search(query) {
keywords.forEach(keyword => {
// From https://github.com/sindresorhus/escape-string-regexp
const regEx = new RegExp(
ignoreDiacriticalMarks(keyword).replace(
escapeHtml(ignoreDiacriticalMarks(keyword)).replace(
/[|\\{}()[\]^$+*?.]/g,
'\\$&'
),
@ -187,10 +187,10 @@ export function search(query) {
let indexTitle = -1;
let indexContent = -1;
handlePostTitle = postTitle
? ignoreDiacriticalMarks(postTitle)
? escapeHtml(ignoreDiacriticalMarks(postTitle))
: postTitle;
handlePostContent = postContent
? ignoreDiacriticalMarks(postContent)
? escapeHtml(ignoreDiacriticalMarks(postContent))
: postContent;
indexTitle = postTitle ? handlePostTitle.search(regEx) : -1;