{"record":{"id":"ec46a47b58a68522","repo":"siyuan-note/siyuan","slug":"invalid-template-path-component","errorCode":null,"errorMessage":"invalid template path component","messagePattern":"invalid template path component","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_manage.go","lineNumber":79,"sourceCode":"\t\treturn errors.New(\"invalid template path\")\n\t}\n\tfor _, part := range strings.Split(p, \"/\") {\n\t\tif strings.HasPrefix(part, \".\") {\n\t\t\treturn errors.New(\"hidden template paths are reserved\")\n\t\t}\n\t}\n\treturn nil\n}\n\n// 新名称保持跨平台可用，已有父目录沿用原名。\nfunc validateNewTemplateName(p string) error {\n\tpart := path.Base(p)\n\tdevice := strings.ToUpper(strings.SplitN(part, \".\", 2)[0])\n\tif device == \"CON\" || device == \"PRN\" || device == \"AUX\" || device == \"NUL\" || (len(device) == 4 && (strings.HasPrefix(device, \"COM\") || strings.HasPrefix(device, \"LPT\")) && device[3] >= '1' && device[3] <= '9') {\n\t\treturn errors.New(\"reserved template file name\")\n\t}\n\tif strings.HasPrefix(part, \".\") || strings.TrimSpace(part) != part || strings.HasSuffix(part, \".\") || strings.ContainsAny(part, \"\\\\:<>\\\"|?*\") || strings.ContainsFunc(part, unicode.IsControl) {\n\t\treturn errors.New(\"invalid template path component\")\n\t}\n\treturn nil\n}\n\n// 清单与目录共同标识模板包，保留目录身份以维持搜索和集市更新。\nfunc isManagedTemplatePackage(root *os.Root, p string) bool {\n\t_, err := root.Lstat(path.Join(p, \"template.json\"))\n\treturn err == nil\n}\n\nfunc openTemplateRoot() (*os.Root, error) {\n\tif err := os.MkdirAll(filepath.Join(util.DataDir, \"templates\"), 0755); err != nil {\n\t\treturn nil, err\n\t}\n\treturn os.OpenRoot(filepath.Join(util.DataDir, \"templates\"))\n}\n\n// 除根目录外不接受符号链接，避免管理操作影响另一个模板包。","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_manage.go#L61-L97","documentation":"validateNewTemplateName rejects any new name component that starts with a dot, has leading/trailing whitespace, ends with a dot, contains \\\\ : < > \" | ? * , or contains Unicode control characters. These characters are illegal or hazardous in Windows filenames, so the kernel enforces a portable name set.","triggerScenarios":"ManageTemplateFiles called with names like '.hidden.md', ' name.md', 'name.', 'a<b>.md', or a name containing a tab/newline.","commonSituations":"Copy-pasting titles with trailing spaces into a rename dialog, template names derived from document titles containing ':' or '?', shell-glob characters left in scripted names.","solutions":["Remove leading/trailing spaces and trailing dots from the name","Replace forbidden characters (\\\\ : < > \" | ? *) with safe ones like '-'","Strip leading dots and control characters before calling ManageTemplateFiles"],"exampleFix":"// before\nManageTemplateFiles(newName: \"report: final?.md\", ...)\n// after\nManageTemplateFiles(newName: \"report - final.md\", ...)","handlingStrategy":"validation","validationCode":"func validNameComponent(part string) bool {\n    if part == \"\" || strings.HasPrefix(part, \".\") || strings.HasSuffix(part, \".\") { return false }\n    if strings.TrimSpace(part) != part { return false }\n    if strings.ContainsAny(part, \"\\\\:<>\\\"|?*\") { return false }\n    return !strings.ContainsFunc(part, unicode.IsControl)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Trim and sanitize names derived from document titles","Replace reserved punctuation with '-' or spaces","Strip control characters from pasted input"],"tags":["naming","windows-compatibility","validation"],"backgroundTag":"invalid-identifier-format","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}