From 67f64f7b2bec3ff6fda7a22f9d9d5c033253f96e Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 8 Dec 2024 23:09:06 +0800 Subject: [PATCH] :bug: Fix HTML tag search escaping https://github.com/siyuan-note/siyuan/issues/13354 --- kernel/model/search.go | 3 +-- kernel/search/mark.go | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/model/search.go b/kernel/model/search.go index dbbeb973074..a18864e10ae 100644 --- a/kernel/model/search.go +++ b/kernel/model/search.go @@ -1459,8 +1459,7 @@ func fullTextSearchCountByFTS(query, boxFilter, pathFilter, typeFilter, ignoreFi } func fullTextSearchByLikeWithRoot(query, boxFilter, pathFilter, typeFilter, ignoreFilter, orderBy string, beforeLen, page, pageSize int) (ret []*Block, matchedBlockCount, matchedRootCount int) { - query = strings.ReplaceAll(query, "'", "''") - query = strings.ReplaceAll(query, "\"", "\"\"") + query = strings.ReplaceAll(query, "'", "''") // 不需要转义双引号,因为条件都是通过单引号包裹的,只需要转义单引号即可 keywords := strings.Split(query, " ") contentField := columnConcat() var likeFilter string diff --git a/kernel/search/mark.go b/kernel/search/mark.go index 5cafc52c0d7..26a99b60189 100644 --- a/kernel/search/mark.go +++ b/kernel/search/mark.go @@ -24,6 +24,7 @@ import ( "github.com/88250/gulu" "github.com/88250/lute/lex" + "github.com/siyuan-note/siyuan/kernel/util" ) func MarkText(text string, keyword string, beforeLen int, caseSensitive bool) (pos int, marked string) { @@ -112,7 +113,7 @@ func EncloseHighlighting(text string, keywords []string, openMark, closeMark str ret = text if reg, err := regexp.Compile(re); err == nil { - ret = reg.ReplaceAllStringFunc(text, func(s string) string { return openMark + s + closeMark }) + ret = reg.ReplaceAllStringFunc(text, func(s string) string { return openMark + util.EscapeHTML(s) + closeMark }) } // 搜索结果预览包含转义符问题 Search results preview contains escape character issue https://github.com/siyuan-note/siyuan/issues/9790