{"record":{"id":"c1d9f0ffa04867a0","repo":"siyuan-note/siyuan","slug":"new-item-template-name-is-empty","errorCode":null,"errorMessage":"new item template name is empty","messagePattern":"new item template name is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/new_item_template.go","lineNumber":64,"sourceCode":"\tfor _, itemTemplate := range config.Templates {\n\t\tif nil == itemTemplate {\n\t\t\tcontinue\n\t\t}\n\t\titemTemplate = cloneNewItemTemplate(itemTemplate)\n\t\tif nil == itemTemplate {\n\t\t\treturn errors.New(\"clone new item template failed\")\n\t\t}\n\t\titemTemplate.Name = strings.TrimSpace(itemTemplate.Name)\n\t\titemTemplate.Icon = strings.TrimSpace(itemTemplate.Icon)\n\t\tif filteredIcon, valid := util.FilterIconValue(itemTemplate.Icon); valid {\n\t\t\titemTemplate.Icon = filteredIcon\n\t\t} else {\n\t\t\t// 非法图标值置空，防止存储可执行标记\n\t\t\t// https://github.com/siyuan-note/siyuan/security/advisories/GHSA-vx5w-qrvp-mmcq\n\t\t\titemTemplate.Icon = \"\"\n\t\t}\n\t\tif \"\" == itemTemplate.Name {\n\t\t\treturn errors.New(\"new item template name is empty\")\n\t\t}\n\t\tif !ast.IsNodeIDPattern(itemTemplate.ID) {\n\t\t\treturn fmt.Errorf(\"invalid new item template id [%s]\", itemTemplate.ID)\n\t\t}\n\t\tif templateIDs[itemTemplate.ID] {\n\t\t\treturn fmt.Errorf(\"duplicated new item template id [%s]\", itemTemplate.ID)\n\t\t}\n\t\ttemplateIDs[itemTemplate.ID] = true\n\t\tif NewItemTargetDetached != itemTemplate.TargetType && NewItemTargetDocument != itemTemplate.TargetType {\n\t\t\treturn fmt.Errorf(\"invalid new item template target type [%s]\", itemTemplate.TargetType)\n\t\t}\n\t\tif NewItemTargetDocument != itemTemplate.TargetType {\n\t\t\titemTemplate.Icon = \"\"\n\t\t\titemTemplate.HideInFileTree = false\n\t\t}\n\t\titemTemplate.ContentTemplatePath = strings.TrimSpace(itemTemplate.ContentTemplatePath)\n\t\tif nil != itemTemplate.SaveLocation {\n\t\t\titemTemplate.SaveLocation.BoxID = strings.TrimSpace(itemTemplate.SaveLocation.BoxID)","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/new_item_template.go#L46-L82","documentation":"Every new-item template must carry a non-empty Name; SetNewItemTemplates rejects the whole config when any template's Name trims to \"\". The Name is what users see when picking a template for new rows.","triggerScenarios":"Calling SetNewItemTemplates with a template whose Name is empty or consists only of whitespace (it is strings.TrimSpace'd before the check).","commonSituations":"UI form allowing an empty template name; JSON payloads omitting the name field; programmatically generated templates without a label.","solutions":["Provide a non-empty, non-whitespace Name for every template in the config.","Validate names client-side before submitting the template configuration.","Fall back to a generated default name (e.g. 'Template 1') when the user left it blank."],"exampleFix":"// before\ncfg.Templates = []*av.NewItemTemplate{{ID: \"20240101120000-abc\"}}\n// after\ncfg.Templates = []*av.NewItemTemplate{{ID: \"20240101120000-abc\", Name: \"Default\"}}","handlingStrategy":"validation","validationCode":"for _, t := range cfg.Templates {\n\tif strings.TrimSpace(t.Name) == \"\" { return errors.New(\"template name required\") }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Require a name in the template-editing UI before save","Trim names client-side to match the kernel's TrimSpace behavior","Auto-generate a fallback name when the field is blank"],"tags":["attribute-view","validation","go"],"backgroundTag":"empty-required-field","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"}