From 07b28ddb486d8c9348f46d81d09874fb90453e78 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 12 Sep 2023 18:00:50 +0800 Subject: [PATCH 1/3] :art: Escape issue --- kernel/model/file.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/model/file.go b/kernel/model/file.go index d8531a06c..786eb3c0a 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -1058,7 +1058,8 @@ func GetHPathsByPaths(paths []string) (hPaths []string, err error) { continue } - hPaths = append(hPaths, box.Name+bt.HPath) + hpath := html.UnescapeString(bt.HPath) + hPaths = append(hPaths, util.EscapeHTML(box.Name)+hpath) } return } From 736256e26aedac5f18a941d93f1db6cf444592bf Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Wed, 13 Sep 2023 08:54:29 +0800 Subject: [PATCH 2/3] :art: Support for symlinked theme folder when exporting HTML https://github.com/siyuan-note/siyuan/issues/9173 --- kernel/model/export.go | 25 +++++++++++++++++++++++-- kernel/util/file.go | 8 ++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/kernel/model/export.go b/kernel/model/export.go index fe6e71707..0346c8fb8 100644 --- a/kernel/model/export.go +++ b/kernel/model/export.go @@ -524,8 +524,19 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string theme = Conf.Appearance.ThemeDark } srcs = []string{"icons", "themes/" + theme} + appearancePath := util.AppearancePath + if util.IsSymlinkPath(util.AppearancePath) { + // Support for symlinked theme folder when exporting HTML https://github.com/siyuan-note/siyuan/issues/9173 + var readErr error + appearancePath, readErr = os.Readlink(util.AppearancePath) + if nil != readErr { + logging.LogErrorf("readlink [%s] failed: %s", util.AppearancePath, readErr) + return + } + } + for _, src := range srcs { - from := filepath.Join(util.AppearancePath, src) + from := filepath.Join(appearancePath, src) to := filepath.Join(savePath, "appearance", src) if err := filelock.Copy(from, to); nil != err { logging.LogErrorf("copy appearance from [%s] to [%s] failed: %s", from, savePath, err) @@ -663,8 +674,18 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, do theme = Conf.Appearance.ThemeDark } srcs = []string{"icons", "themes/" + theme} + appearancePath := util.AppearancePath + if util.IsSymlinkPath(util.AppearancePath) { + // Support for symlinked theme folder when exporting HTML https://github.com/siyuan-note/siyuan/issues/9173 + var readErr error + appearancePath, readErr = os.Readlink(util.AppearancePath) + if nil != readErr { + logging.LogErrorf("readlink [%s] failed: %s", util.AppearancePath, readErr) + return + } + } for _, src := range srcs { - from := filepath.Join(util.AppearancePath, src) + from := filepath.Join(appearancePath, src) to := filepath.Join(savePath, "appearance", src) if err := filelock.Copy(from, to); nil != err { logging.LogErrorf("copy appearance from [%s] to [%s] failed: %s", from, savePath, err) diff --git a/kernel/util/file.go b/kernel/util/file.go index e8ec1aed0..5f717553b 100644 --- a/kernel/util/file.go +++ b/kernel/util/file.go @@ -31,6 +31,14 @@ import ( "github.com/siyuan-note/logging" ) +func IsSymlinkPath(absPath string) bool { + fi, err := os.Lstat(absPath) + if nil != err { + return false + } + return 0 != fi.Mode()&os.ModeSymlink +} + func IsEmptyDir(p string) bool { if !gulu.File.IsDir(p) { return false From d9973826449e524dfaef91fcefff7bb0e6e0eae6 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Wed, 13 Sep 2023 08:58:25 +0800 Subject: [PATCH 3/3] :art: Refactor symlink read --- kernel/model/export.go | 4 ++-- kernel/util/working.go | 11 +++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/kernel/model/export.go b/kernel/model/export.go index 0346c8fb8..6d22d6dda 100644 --- a/kernel/model/export.go +++ b/kernel/model/export.go @@ -528,7 +528,7 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string if util.IsSymlinkPath(util.AppearancePath) { // Support for symlinked theme folder when exporting HTML https://github.com/siyuan-note/siyuan/issues/9173 var readErr error - appearancePath, readErr = os.Readlink(util.AppearancePath) + appearancePath, readErr = filepath.EvalSymlinks(util.AppearancePath) if nil != readErr { logging.LogErrorf("readlink [%s] failed: %s", util.AppearancePath, readErr) return @@ -678,7 +678,7 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, do if util.IsSymlinkPath(util.AppearancePath) { // Support for symlinked theme folder when exporting HTML https://github.com/siyuan-note/siyuan/issues/9173 var readErr error - appearancePath, readErr = os.Readlink(util.AppearancePath) + appearancePath, readErr = filepath.EvalSymlinks(util.AppearancePath) if nil != readErr { logging.LogErrorf("readlink [%s] failed: %s", util.AppearancePath, readErr) return diff --git a/kernel/util/working.go b/kernel/util/working.go index 77bc45485..6cc8cfd90 100644 --- a/kernel/util/working.go +++ b/kernel/util/working.go @@ -392,15 +392,10 @@ func initMime() { func GetDataAssetsAbsPath() (ret string) { ret = filepath.Join(DataDir, "assets") - var err error - stat, err := os.Lstat(ret) - if nil != err { - logging.LogErrorf("stat assets failed: %s", err) - return - } - if 0 != stat.Mode()&os.ModeSymlink { + if IsSymlinkPath(ret) { // 跟随符号链接 https://github.com/siyuan-note/siyuan/issues/5480 - ret, err = os.Readlink(ret) + var err error + ret, err = filepath.EvalSymlinks(ret) if nil != err { logging.LogErrorf("read assets link failed: %s", err) }