From 9dc68a28e47db25ca2f9e8d832ef5fb7d521c6cd Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 14 Nov 2023 22:00:48 +0800 Subject: [PATCH 1/3] :art: Improve logging --- kernel/model/index_fix.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/model/index_fix.go b/kernel/model/index_fix.go index f6c51eeea..70b317225 100644 --- a/kernel/model/index_fix.go +++ b/kernel/model/index_fix.go @@ -74,7 +74,7 @@ func removeDuplicateDatabaseRefs() { } if 0 < len(duplicatedRootIDs) { - logging.LogWarnf("exist more than one ref duplicated [%d], reindex it", duplicatedRootIDs) + logging.LogWarnf("exist more than one ref duplicated [%d], reindex it", len(duplicatedRootIDs)) } } From ea2a2bbf03567f8e81a2cc2e8db12579f23ccea0 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 14 Nov 2023 22:35:46 +0800 Subject: [PATCH 2/3] :art: Code content in templates is not properly escaped https://github.com/siyuan-note/siyuan/issues/9649 --- kernel/model/template.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/kernel/model/template.go b/kernel/model/template.go index e3f9485dc..daa58f365 100644 --- a/kernel/model/template.go +++ b/kernel/model/template.go @@ -20,7 +20,6 @@ import ( "bytes" "errors" "fmt" - "github.com/siyuan-note/siyuan/kernel/av" "io/fs" "os" "path/filepath" @@ -33,10 +32,11 @@ import ( "github.com/88250/lute/ast" "github.com/88250/lute/parse" "github.com/88250/lute/render" - sprig "github.com/Masterminds/sprig/v3" + "github.com/Masterminds/sprig/v3" "github.com/araddon/dateparse" "github.com/siyuan-note/filelock" "github.com/siyuan-note/logging" + "github.com/siyuan-note/siyuan/kernel/av" "github.com/siyuan-note/siyuan/kernel/search" "github.com/siyuan-note/siyuan/kernel/sql" "github.com/siyuan-note/siyuan/kernel/treenode" @@ -147,6 +147,25 @@ func DocSaveAsTemplate(id, name string, overwrite bool) (code int, err error) { tree := prepareExportTree(bt) addBlockIALNodes(tree, true) + ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus { + if !entering { + return ast.WalkContinue + } + + // Code content in templates is not properly escaped https://github.com/siyuan-note/siyuan/issues/9649 + switch n.Type { + case ast.NodeCodeBlockCode: + n.Tokens = bytes.ReplaceAll(n.Tokens, []byte("""), []byte("\"")) + case ast.NodeCodeSpanContent: + n.Tokens = bytes.ReplaceAll(n.Tokens, []byte("""), []byte("\"")) + case ast.NodeTextMark: + if n.IsTextMarkType("code") { + n.TextMarkTextContent = strings.ReplaceAll(n.TextMarkTextContent, """, "\"") + } + } + return ast.WalkContinue + }) + luteEngine := NewLute() formatRenderer := render.NewFormatRenderer(tree, luteEngine.RenderOptions) md := formatRenderer.Render() From 78d403a740818a8bf6781225fddd761faf8b4638 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 14 Nov 2023 22:37:05 +0800 Subject: [PATCH 3/3] :memo: Update changelogs --- app/changelogs/v2.10.15/v2.10.15.md | 1 + app/changelogs/v2.10.15/v2.10.15_zh_CHT.md | 1 + app/changelogs/v2.10.15/v2.10.15_zh_CN.md | 1 + 3 files changed, 3 insertions(+) diff --git a/app/changelogs/v2.10.15/v2.10.15.md b/app/changelogs/v2.10.15/v2.10.15.md index bff559564..41e6ed891 100644 --- a/app/changelogs/v2.10.15/v2.10.15.md +++ b/app/changelogs/v2.10.15/v2.10.15.md @@ -35,6 +35,7 @@ Below are the detailed changes in this version. * [Editor missing after close all tabs when has pin tabs](https://github.com/siyuan-note/siyuan/issues/9624) * [Data synchronization accidentally deletes local files](https://github.com/siyuan-note/siyuan/issues/9631) * [The window title is hidden after the graph is minimized](https://github.com/siyuan-note/siyuan/issues/9638) +* [Code content in templates is not properly escaped](https://github.com/siyuan-note/siyuan/issues/9649) ### Document diff --git a/app/changelogs/v2.10.15/v2.10.15_zh_CHT.md b/app/changelogs/v2.10.15/v2.10.15_zh_CHT.md index 1f5001dd3..62db90cde 100644 --- a/app/changelogs/v2.10.15/v2.10.15_zh_CHT.md +++ b/app/changelogs/v2.10.15/v2.10.15_zh_CHT.md @@ -35,6 +35,7 @@ * [存在固定頁籤時關閉所有頁籤導致編輯器異常](https://github.com/siyuan-note/siyuan/issues/9624) * [資料同步誤刪本機檔案](https://github.com/siyuan-note/siyuan/issues/9631) * [關係圖最小化後視窗標題被隱藏](https://github.com/siyuan-note/siyuan/issues/9638) +* [未正確轉義範本程式碼內容](https://github.com/siyuan-note/siyuan/issues/9649) ### 改進文檔 diff --git a/app/changelogs/v2.10.15/v2.10.15_zh_CN.md b/app/changelogs/v2.10.15/v2.10.15_zh_CN.md index 34e3a3734..c16dd3732 100644 --- a/app/changelogs/v2.10.15/v2.10.15_zh_CN.md +++ b/app/changelogs/v2.10.15/v2.10.15_zh_CN.md @@ -35,6 +35,7 @@ * [存在固定页签时关闭所有页签导致编辑器异常](https://github.com/siyuan-note/siyuan/issues/9624) * [数据同步误删本地文件](https://github.com/siyuan-note/siyuan/issues/9631) * [关系图最小化后窗口标题被隐藏](https://github.com/siyuan-note/siyuan/issues/9638) +* [未正确转义模板代码内容](https://github.com/siyuan-note/siyuan/issues/9649) ### 改进文档