🎨 Limit the database title to 512 characters https://github.com/siyuan-note/siyuan/issues/15459

This commit is contained in:
Daniel 2025-08-24 11:25:38 +08:00
parent 4a5237dbd0
commit af3220f241
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 6 additions and 2 deletions

View file

@ -27,6 +27,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
"unicode/utf8"
"github.com/88250/gulu" "github.com/88250/gulu"
"github.com/88250/lute/ast" "github.com/88250/lute/ast"
@ -2745,7 +2746,7 @@ func (tx *Transaction) setAttributeViewName(operation *Operation) (err error) {
attrView.Name = strings.TrimSpace(operation.Data.(string)) attrView.Name = strings.TrimSpace(operation.Data.(string))
attrView.Name = strings.ReplaceAll(attrView.Name, "\n", " ") attrView.Name = strings.ReplaceAll(attrView.Name, "\n", " ")
if 512 < len(attrView.Name) { if 512 < utf8.RuneCountInString(attrView.Name) {
attrView.Name = gulu.Str.SubStr(attrView.Name, 512) attrView.Name = gulu.Str.SubStr(attrView.Name, 512)
} }
err = av.SaveAttributeView(attrView) err = av.SaveAttributeView(attrView)

View file

@ -101,9 +101,12 @@ func checkAttrView(attrView *av.AttributeView, view *av.View) {
} }
} }
if strings.Contains(attrView.Name, "\n") {
attrView.Name = strings.ReplaceAll(attrView.Name, "\n", " ")
}
// 截断超长的数据库标题 Limit the database title to 512 characters https://github.com/siyuan-note/siyuan/issues/15459 // 截断超长的数据库标题 Limit the database title to 512 characters https://github.com/siyuan-note/siyuan/issues/15459
if 512 < utf8.RuneCountInString(attrView.Name) { if 512 < utf8.RuneCountInString(attrView.Name) {
attrView.Name = strings.ReplaceAll(attrView.Name, "\n", " ")
attrView.Name = gulu.Str.SubStr(attrView.Name, 512) attrView.Name = gulu.Str.SubStr(attrView.Name, 512)
changed = true changed = true
} }