mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-17 09:30:48 +08:00
🐛 File system exception when exporting docs containing ../
hyperlinks to Markdown Fix https://github.com/siyuan-note/siyuan/issues/9779
This commit is contained in:
parent
ee351057f1
commit
c9f90c606e
@ -432,7 +432,7 @@ func SearchAssetsByName(keyword string, exts []string) (ret []*cache.Asset) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAssetAbsPath(relativePath string) (absPath string, err error) {
|
func GetAssetAbsPath(relativePath string) (ret string, err error) {
|
||||||
relativePath = strings.TrimSpace(relativePath)
|
relativePath = strings.TrimSpace(relativePath)
|
||||||
if strings.Contains(relativePath, "?") {
|
if strings.Contains(relativePath, "?") {
|
||||||
relativePath = relativePath[:strings.Index(relativePath, "?")]
|
relativePath = relativePath[:strings.Index(relativePath, "?")]
|
||||||
@ -455,13 +455,18 @@ func GetAssetAbsPath(relativePath string) (absPath string, err error) {
|
|||||||
}
|
}
|
||||||
if p := filepath.ToSlash(path); strings.HasSuffix(p, relativePath) {
|
if p := filepath.ToSlash(path); strings.HasSuffix(p, relativePath) {
|
||||||
if gulu.File.IsExist(path) {
|
if gulu.File.IsExist(path) {
|
||||||
absPath = path
|
ret = path
|
||||||
return io.EOF
|
return io.EOF
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if "" != absPath {
|
|
||||||
|
if "" != ret {
|
||||||
|
if !util.IsSubPath(util.WorkspaceDir, ret) {
|
||||||
|
err = fmt.Errorf("[%s] is not sub path of workspace", ret)
|
||||||
|
return
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -469,7 +474,11 @@ func GetAssetAbsPath(relativePath string) (absPath string, err error) {
|
|||||||
// 在全局 assets 路径下搜索
|
// 在全局 assets 路径下搜索
|
||||||
p := filepath.Join(util.DataDir, relativePath)
|
p := filepath.Join(util.DataDir, relativePath)
|
||||||
if gulu.File.IsExist(p) {
|
if gulu.File.IsExist(p) {
|
||||||
absPath = p
|
ret = p
|
||||||
|
if !util.IsSubPath(util.WorkspaceDir, ret) {
|
||||||
|
err = fmt.Errorf("[%s] is not sub path of workspace", ret)
|
||||||
|
return
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return "", errors.New(fmt.Sprintf(Conf.Language(12), relativePath))
|
return "", errors.New(fmt.Sprintf(Conf.Language(12), relativePath))
|
||||||
|
@ -190,6 +190,10 @@ func IsSubPath(absPath, toCheckPath string) bool {
|
|||||||
if 1 > len(absPath) || 1 > len(toCheckPath) {
|
if 1 > len(absPath) || 1 > len(toCheckPath) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if absPath == toCheckPath { // 相同路径时不认为是子路径
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
if gulu.OS.IsWindows() {
|
if gulu.OS.IsWindows() {
|
||||||
if filepath.IsAbs(absPath) && filepath.IsAbs(toCheckPath) {
|
if filepath.IsAbs(absPath) && filepath.IsAbs(toCheckPath) {
|
||||||
if strings.ToLower(absPath)[0] != strings.ToLower(toCheckPath)[0] {
|
if strings.ToLower(absPath)[0] != strings.ToLower(toCheckPath)[0] {
|
||||||
|
@ -268,9 +268,12 @@ func IsDisplayableAsset(p string) bool {
|
|||||||
|
|
||||||
func GetAbsPathInWorkspace(relPath string) (string, error) {
|
func GetAbsPathInWorkspace(relPath string) (string, error) {
|
||||||
absPath := filepath.Join(WorkspaceDir, relPath)
|
absPath := filepath.Join(WorkspaceDir, relPath)
|
||||||
|
if WorkspaceDir == absPath {
|
||||||
|
return absPath, nil
|
||||||
|
}
|
||||||
|
|
||||||
if IsSubPath(WorkspaceDir, absPath) {
|
if IsSubPath(WorkspaceDir, absPath) {
|
||||||
return absPath, nil
|
return absPath, nil
|
||||||
} else {
|
|
||||||
return "", os.ErrPermission
|
|
||||||
}
|
}
|
||||||
|
return "", os.ErrPermission
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user