@@ -159,6 +159,8 @@ export function search(query) {
159159 const post = data [ i ] ;
160160 let matchesScore = 0 ;
161161 let resultStr = '' ;
162+ let handlePostTitle = '' ;
163+ let handlePostContent = '' ;
162164 const postTitle = post . title && post . title . trim ( ) ;
163165 const postContent = post . body && post . body . trim ( ) ;
164166 const postUrl = post . slug || '' ;
@@ -167,21 +169,23 @@ export function search(query) {
167169 keywords . forEach ( keyword => {
168170 // From https://github.com/sindresorhus/escape-string-regexp
169171 const regEx = new RegExp (
170- ignoreDiacriticalMarks ( keyword ) . replace (
172+ escapeHtml ( ignoreDiacriticalMarks ( keyword ) ) . replace (
171173 / [ | \\ { } ( ) [ \] ^ $ + * ? . ] / g,
172174 '\\$&'
173175 ) ,
174176 'gi'
175177 ) ;
176178 let indexTitle = - 1 ;
177179 let indexContent = - 1 ;
180+ handlePostTitle = postTitle
181+ ? escapeHtml ( ignoreDiacriticalMarks ( postTitle ) )
182+ : postTitle ;
183+ handlePostContent = postContent
184+ ? escapeHtml ( ignoreDiacriticalMarks ( postContent ) )
185+ : postContent ;
178186
179- indexTitle = postTitle
180- ? ignoreDiacriticalMarks ( postTitle ) . search ( regEx )
181- : - 1 ;
182- indexContent = postContent
183- ? ignoreDiacriticalMarks ( postContent ) . search ( regEx )
184- : - 1 ;
187+ indexTitle = postTitle ? handlePostTitle . search ( regEx ) : - 1 ;
188+ indexContent = postContent ? handlePostContent . search ( regEx ) : - 1 ;
185189
186190 if ( indexTitle >= 0 || indexContent >= 0 ) {
187191 matchesScore += indexTitle >= 0 ? 3 : indexContent >= 0 ? 2 : 0 ;
@@ -201,7 +205,8 @@ export function search(query) {
201205
202206 const matchContent =
203207 '...' +
204- escapeHtml ( ignoreDiacriticalMarks ( postContent ) )
208+ // handlePostContent
209+ handlePostContent
205210 . substring ( start , end )
206211 . replace (
207212 regEx ,
@@ -215,7 +220,7 @@ export function search(query) {
215220
216221 if ( matchesScore > 0 ) {
217222 const matchingPost = {
218- title : escapeHtml ( ignoreDiacriticalMarks ( postTitle ) ) ,
223+ title : handlePostTitle ,
219224 content : postContent ? resultStr : '' ,
220225 url : postUrl ,
221226 score : matchesScore ,
0 commit comments