🎨 限制文档名称最大长度为 512 https://github.com/siyuan-note/siyuan/issues/6299

This commit is contained in:
Liang Ding 2022-10-22 01:25:22 +08:00
parent f9784e2b83
commit cff937a384
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
6 changed files with 16 additions and 5 deletions

View file

@ -29,6 +29,7 @@ import (
"strconv"
"strings"
"time"
"unicode/utf8"
"github.com/88250/gulu"
"github.com/88250/lute/ast"
@ -1268,6 +1269,11 @@ func RenameDoc(boxID, p, title string) (err error) {
}
title = gulu.Str.RemoveInvisible(title)
if 512 < utf8.RuneCountInString(title) {
// 限制文档名称最大长度为 `512` https://github.com/siyuan-note/siyuan/issues/6299
return errors.New(Conf.Language(106))
}
oldTitle := tree.Root.IALAttr("title")
if oldTitle == title {
return
@ -1386,6 +1392,11 @@ func CreateDailyNote(boxID string) (p string, existed bool, err error) {
func createDoc(boxID, p, title, dom string) (err error) {
title = gulu.Str.RemoveInvisible(title)
if 512 < utf8.RuneCountInString(title) {
// 限制文档名称最大长度为 `512` https://github.com/siyuan-note/siyuan/issues/6299
return errors.New(Conf.Language(106))
}
baseName := strings.TrimSpace(path.Base(p))
if "" == strings.TrimSuffix(baseName, ".sy") {
return errors.New(Conf.Language(16))