{"id":"f4115c0dc3c07ed2","repo":"gohugoio/hugo","slug":"alias-is-an-empty-string","errorCode":null,"errorMessage":"alias \"\" is an empty string","messagePattern":"alias \"\" is an empty string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/alias.go","lineNumber":126,"sourceCode":"\n\tpd := publisher.Descriptor{\n\t\tSrc:          aliasContent,\n\t\tTargetPath:   targetPath,\n\t\tStatCounter:  &s.PathSpec.ProcessingStats.Aliases,\n\t\tOutputFormat: outputFormat,\n\t}\n\n\tif s.conf.RelativeURLs || s.conf.CanonifyURLs {\n\t\tpd.AbsURLPath = s.absURLPath(targetPath)\n\t}\n\n\treturn s.publisher.Publish(pd)\n}\n\nfunc (a aliasHandler) targetPathAlias(src string, of output.Format) (string, error) {\n\toriginalAlias := src\n\tif len(src) <= 0 {\n\t\treturn \"\", fmt.Errorf(\"alias \\\"\\\" is an empty string\")\n\t}\n\n\talias := path.Clean(filepath.ToSlash(src))\n\n\tif !a.allowRoot && alias == \"/\" {\n\t\treturn \"\", fmt.Errorf(\"alias \\\"%s\\\" resolves to website root directory\", originalAlias)\n\t}\n\n\tcomponents := strings.Split(alias, \"/\")\n\n\t// Validate against directory traversal\n\tif components[0] == \"..\" {\n\t\treturn \"\", fmt.Errorf(\"alias \\\"%s\\\" traverses outside the website root directory\", originalAlias)\n\t}\n\n\t// Handle Windows file and directory naming restrictions\n\t// See \"Naming Files, Paths, and Namespaces\" on MSDN\n\t// https://msdn.microsoft.com/en-us/library/aa365247%28v=VS.85%29.aspx?f=255&MSPPError=-2147217396","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/hugolib/alias.go#L108-L144","documentation":"Returned by targetPathAlias (hugolib/alias.go:126) when an alias source path is the empty string. An empty alias cannot be turned into an output file path, so Hugo rejects it before cleaning and validating the path (a \"/\" alias is separately rejected as resolving to the site root).","triggerScenarios":"A page whose front matter aliases list contains an empty entry — aliases: [\"\"] or a YAML list item left blank — passed into publishDestAlias during rendering.","commonSituations":"Archetype templates with a placeholder aliases field left empty, trailing commas or blank list items in YAML/TOML front matter, or scripts that generate aliases from a field that is sometimes empty (e.g. an old-URL field missing on some pages).","solutions":["Find the offending page and remove the empty entry from its aliases list.","Search content for empty alias entries: grep -rn 'aliases' content/ and check for blank items.","If aliases are generated by tooling or archetypes, skip emitting the field when the source value is empty."],"exampleFix":"# before (front matter)\naliases:\n  - \"\"\n  - /old-url/\n# after\naliases:\n  - /old-url/","handlingStrategy":"validation","validationCode":"for _, a := range page.Aliases {\n    if strings.TrimSpace(a) == \"\" {\n        return fmt.Errorf(\"page %s: empty alias\", page.Path())\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never emit empty strings into the aliases front matter list; filter blanks in any content-generation script","Lint front matter in CI for empty or whitespace-only alias entries","When templating front matter, guard against unset variables producing aliases: [\"\"]"],"tags":["hugo","alias","front-matter","validation"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}