An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Preserve single-character escaping in graph tag queries https://github.com/siyuan-note/siyuan/pull/20620
Danielfae043b519df
diff --git a/kernel/model/graph.go b/kernel/model/graph.goindex f3b763a7d0..656f1aaf96 100644--- a/kernel/model/graph.go+++ b/kernel/model/graph.go@@ -740,7 +740,7 @@ func query2Stmt(queryStr string) (ret string) {for i, tag := range tags {buf.WriteString("ial LIKE '%tags=\"%")buf.WriteString(conf.EscapeSearchLikePattern(tag))- buf.WriteString("%\"%' ESCAPE '\\\\'")+ buf.WriteString("%\"%' ESCAPE '\\'")if i < len(tags)-1 {buf.WriteString(" AND ")}diff --git a/kernel/model/graph_test.go b/kernel/model/graph_test.goindex e3e11b7037..435e2fceda 100644--- a/kernel/model/graph_test.go+++ b/kernel/model/graph_test.go@@ -88,6 +88,42 @@ func TestGraphSearchLiteralWildcards(t *testing.T) {}}+func TestGraphSearchTagAttributes(t *testing.T) {+ previous := Conf+ Conf = &AppConf{Search: NewConfSection(conf.NewSearch())}+ t.Cleanup(func() { Conf = previous })+ db, err := gosql.Open("sqlite3_extended", ":memory:")+ if err != nil {+ t.Fatal(err)+ }+ defer db.Close()+ for _, tag := range []string{"foo", "a_b", "a%b", `a\b`, "a'b"} {+ query := "SELECT " + query2Stmt(`<span data-type="tag">`+tag+`</span>`) ++ " FROM (SELECT ? AS content, '' AS name, '' AS alias, '' AS memo, ? AS ial)"+ for _, test := range []struct {+ name, content, ial string+ want bool+ }{+ {"attribute-tag", "plain text", `{: tags="` + tag + `"}`, true},+ {"other-tag", "plain text", `{: tags="unrelated axb"}`, false},+ {"other-attribute", "plain text", `{: name="` + tag + `"}`, false},+ {"inline-tag", "#" + tag + "#", `{: name="other"}`, true},+ {"empty-attributes", "plain text", "", false},+ {"inline-tag-empty-attributes", "#" + tag + "#", "", true},+ } {+ t.Run(tag+"/"+test.name, func(t *testing.T) {+ var matched bool+ if err := db.QueryRow(query, test.content, test.ial).Scan(&matched); err != nil {+ t.Fatalf("%s: %v", query, err)+ }+ if matched != test.want {+ t.Fatalf("content %q ial %q: matched=%v, want %v", test.content, test.ial, matched, test.want)+ }+ })+ }+ }+}+func TestMarkLinkedNodesWithSize(t *testing.T) {nodes := []*GraphNode{{ID: "a", Size: 10},