siyuan-note/siyuan · error
invalid template path component
Error message
invalid template path component
What it means
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.
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
Example fix
// before ManageTemplateFiles(newName: "report: final?.md", ...) // after ManageTemplateFiles(newName: "report - final.md", ...)
Defensive patterns
Strategy: validation
Validate before calling
func validNameComponent(part string) bool {
if part == "" || strings.HasPrefix(part, ".") || strings.HasSuffix(part, ".") { return false }
if strings.TrimSpace(part) != part { return false }
if strings.ContainsAny(part, "\\:<>\"|?*") { return false }
return !strings.ContainsFunc(part, unicode.IsControl)
} Prevention
- Trim and sanitize names derived from document titles
- Replace reserved punctuation with '-' or spaces
- Strip control characters from pasted input
When it happens
Trigger: ManageTemplateFiles called with names like '.hidden.md', ' name.md', 'name.', 'a<b>.md', or a name containing a tab/newline.
Common situations: 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.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/ec46a47b58a68522.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/template_manage.go:79
return errors.New("invalid template path")
}
for _, part := range strings.Split(p, "/") {
if strings.HasPrefix(part, ".") {
return errors.New("hidden template paths are reserved")
}
}
return nil
}
// 新名称保持跨平台可用,已有父目录沿用原名。
func validateNewTemplateName(p string) error {
part := path.Base(p)
device := strings.ToUpper(strings.SplitN(part, ".", 2)[0])
if 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') {
return errors.New("reserved template file name")
}
if strings.HasPrefix(part, ".") || strings.TrimSpace(part) != part || strings.HasSuffix(part, ".") || strings.ContainsAny(part, "\\:<>\"|?*") || strings.ContainsFunc(part, unicode.IsControl) {
return errors.New("invalid template path component")
}
return nil
}
// 清单与目录共同标识模板包,保留目录身份以维持搜索和集市更新。
func isManagedTemplatePackage(root *os.Root, p string) bool {
_, err := root.Lstat(path.Join(p, "template.json"))
return err == nil
}
func openTemplateRoot() (*os.Root, error) {
if err := os.MkdirAll(filepath.Join(util.DataDir, "templates"), 0755); err != nil {
return nil, err
}
return os.OpenRoot(filepath.Join(util.DataDir, "templates"))
}
// 除根目录外不接受符号链接,避免管理操作影响另一个模板包。View on GitHub (pinned to 9f775e8a12)