An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Optimize isValidAttrName function performance (#16755)
Jeffrey Chen76e23e67163b
diff --git a/kernel/model/blockial.go b/kernel/model/blockial.goindex b333c81c1d..fb06aa3d1b 100644--- a/kernel/model/blockial.go+++ b/kernel/model/blockial.go@@ -36,30 +36,44 @@ import ("github.com/siyuan-note/siyuan/kernel/util")+// validateChars 验证从指定索引开始的字符是否合法(小写字母、数字、连字符)+func validateChars(name string, startIdx, n int) bool {+ for i := startIdx; i < n; i++ {+ c := name[i]+ if c != '-' && (c < 'a' || c > 'z') && (c < '0' || c > '9') {+ return false+ }+ }+ return true+}+// isValidAttrName 验证属性名是否合法func isValidAttrName(name string) bool {- if len(name) == 0 {+ n := len(name)+ if n == 0 {return false}// 首字符必须是小写字母- if name[0] < 'a' || name[0] > 'z' {+ c := name[0]+ if c < 'a' || c > 'z' {return false}- // 自定义属性 custom- 之后的首个字符必须是小写字母- if strings.HasPrefix(name, "custom-") {- if len(name) <= 7 || name[7] < 'a' || name[7] > 'z' {- return false- }- }// 后续字符只能是小写字母、数字、连字符- for i := 1; i < len(name); i++ {- c := name[i]- if c == '-' || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') {- continue+ if c != 'c' {+ return validateChars(name, 1, n)+ }+ // 首字符是 'c',检查自定义属性 custom- 前缀+ if n >= 7 && name[1] == 'u' && name[2] == 's' && name[3] == 't' && name[4] == 'o' && name[5] == 'm' && name[6] == '-' {+ if n == 7 {+ return false // 不允许只包含前缀}- return false+ if c = name[7]; c < 'a' || c > 'z' {+ return false // 首字符必须是小写字母+ }+ return validateChars(name, 7, n)}- return true+ // 非自定义属性+ return validateChars(name, 1, n)}func SetBlockReminder(id string, timed string) (err error) {