{"record":{"id":"b57032e36b49f06d","repo":"siyuan-note/siyuan","slug":"hidden-template-paths-are-reserved","errorCode":null,"errorMessage":"hidden template paths are reserved","messagePattern":"hidden template paths are reserved","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_manage.go","lineNumber":65,"sourceCode":"}\n\ntype TemplateFileEntry struct {\n\tPath      string `json:\"path\"`\n\tIsDir     bool   `json:\"isDir\"`\n\tIsPackage bool   `json:\"isPackage,omitempty\"`\n}\n\n// 访问已有模板只校验目录边界，不对文件名进行清理或改写。\nfunc validateTemplateRelativePath(p string, allowRoot bool) error {\n\tif p == \"\" && allowRoot {\n\t\treturn nil\n\t}\n\tif p == \"\" || !fs.ValidPath(p) || strings.ContainsAny(p, \"\\\\:\\x00\") {\n\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","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_manage.go#L47-L83","documentation":"validateTemplateRelativePath rejects any path segment starting with a dot, reserving hidden files/directories inside the templates tree. This prevents templates from colliding with metadata, lock, or system files that the kernel stores in dot-prefixed entries.","triggerScenarios":"Calling DocSaveAsTemplateInDirectory or checkTemplateFilePath with any segment beginning with '.', e.g. '.hidden/x.md', 'notes/.config.md', or a directory named '.tmp'.","commonSituations":"Users naming a template folder starting with a dot for 'invisibility', tools that create dot-directories (.git, .obsidian) inside the templates folder, or exporting from another app that prefixes temp names with '.'.","solutions":["Rename the file or directory so no segment starts with '.'","Move templates out of dot-prefixed directories into normal ones","Strip leading dots from user-supplied names before calling the API"],"exampleFix":"// before\nDocSaveAsTemplateInDirectory(\".hidden/tpl.md\", ...)\n// after\nDocSaveAsTemplateInDirectory(\"hidden/tpl.md\", ...)","handlingStrategy":"validation","validationCode":"func hasHiddenSegment(p string) bool {\n    for _, part := range strings.Split(p, \"/\") {\n        if strings.HasPrefix(part, \".\") { return true }\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":"if err := validateTemplateRelativePath(p, false); err != nil { /* prompt user to rename dot-prefixed entries */ }","preventionTips":["Avoid dot-prefixed names for template files and folders","Keep tool metadata (.git etc.) out of the templates directory"],"tags":["path-validation","naming","templates"],"backgroundTag":"invalid-argument-value","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"}