{"record":{"id":"b393cf7d443e642d","repo":"siyuan-note/siyuan","slug":"maximum-length-is-limited-to-512-characters","errorCode":null,"errorMessage":"Maximum length is limited to 512 characters","messagePattern":"Maximum length is limited to 512 characters","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/model/file.go","lineNumber":2155,"sourceCode":"\nfunc renameDoc0(boxID, p, title string) (err error) {\n\tbox := Conf.Box(boxID)\n\tif nil == box {\n\t\terr = errors.New(Conf.Language(0))\n\t\treturn\n\t}\n\n\tFlushTxQueue()\n\tluteEngine := util.NewLute()\n\ttree, err := filesys.LoadTree(box.ID, p, luteEngine)\n\tif err != nil {\n\t\treturn\n\t}\n\n\ttitle = normalizeDocTitle(title)\n\tif 512 < utf8.RuneCountInString(title) {\n\t\t// 限制笔记本名和文档名最大长度为 `512` https://github.com/siyuan-note/siyuan/issues/6299\n\t\treturn errors.New(Conf.Language(106))\n\t}\n\n\tvar isEmpty bool\n\tif \"\" == title {\n\t\ttitle = Conf.language(16)\n\t\tisEmpty = true\n\t}\n\t// 先规范化输入得到实际会存储的标题，再与旧标题比较\n\ttitleChanged := tree.Root.IALAttr(\"title\") != title\n\n\tvar emptyAttrUpdated bool\n\tif titleChanged {\n\t\ttree.HPath = path.Join(path.Dir(tree.HPath), title)\n\t\ttree.Root.SetIALAttr(\"title\", title)\n\t}\n\n\t// 按需同步“无标题”标记（仅更新 IAL，不触发子树重命名等）\n\tisTitleEmpty := tree.Root.IALAttr(NodeAttrTitleEmpty) == \"true\"","sourceCodeStart":2137,"sourceCodeEnd":2173,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/model/file.go#L2137-L2173","documentation":"Thrown by renameDoc0 when the new document title exceeds 512 Unicode runes (not bytes). Conf.Language(106) = 'Maximum length is limited to 512 characters'. The check uses utf8.RuneCountInString(title) after normalizeDocTitle, so the limit applies to the normalized title. This addresses issue #6299 which capped excessively long names.","triggerScenarios":"Calling RenameDoc(boxID, p, title) where the normalized title has more than 512 runes. This happens when a user pastes a very long string, or a programmatic rename uses auto-generated titles from content that exceeds the limit.","commonSituations":"A user renames a document using a full paragraph or very long heading. An import or sync operation generates a title from document content that exceeds 512 runes. A plugin auto-titles from the first block without truncation.","solutions":["Truncate the title to 512 runes before calling RenameDoc: title = substring by rune count.","In UI code, enforce a maxlength on the rename input field.","For programmatic callers, check utf8.RuneCountInString(title) > 512 and truncate or warn the user.","If a longer title is essential, store the full text in a custom IAL attribute instead of the document title."],"exampleFix":"// before\nerr := model.RenameDoc(boxID, p, title)\n\n// after\nif runes := utf8.RuneCountInString(title); runes > 512 {\n    runified := []rune(title)\n    title = string(runified[:512])\n}\nerr := model.RenameDoc(boxID, p, title)","handlingStrategy":"validation","validationCode":"// Pre-check: enforce 512-rune limit on title\ntitle = model.NormalizeDocTitle(title)\nif utf8.RuneCountInString(title) > 512 {\n    title = string([]rune(title)[:512])\n}","typeGuard":"func titleWithinLimit(title string) bool {\n    return utf8.RuneCountInString(title) <= 512\n}","tryCatchPattern":null,"preventionTips":["Check utf8.RuneCountInString(title) before calling RenameDoc.","Truncate titles to 512 runes (not bytes — multi-byte characters matter).","Enforce maxlength on rename input fields in UI code.","Store excessively long text in a custom IAL attribute if needed."],"tags":["rename","validation","length-limit","title"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}