{"record":{"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":"warning","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/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/hugolib/alias.go#L108-L144","documentation":"Returned by aliasHandler.targetPathAlias (hugolib/alias.go) when the alias source string passed in is empty (len(src) <= 0). Aliases come from page front matter (the 'aliases' / 'alias' array) or redirects; an empty entry cannot map to a target file and is rejected outright.","triggerScenarios":"A page's front matter contains an empty alias string, e.g. aliases: [\"\", \"/old/\"] or aliases: [] with a stray empty element produced by a template generating front matter. Also any programmatic call to publishDestAlias/writeDestAlias with an empty path argument.","commonSituations":"Content authors hand-editing front matter and leaving a blank list item; a headless CMS or generator emitting aliases: [\"\"]; migrating from 'alias' (singular, deprecated) to 'aliases' and leaving an empty value; templated content where the alias variable resolves to empty.","solutions":["Search the content tree for aliases: entries containing an empty string and remove them.","If aliases are generated by a template/shortcode, guard so empty values are not emitted into front matter.","Validate front matter with a linter (e.g. hugo --renderToMemory plus a YAML lint) before building.","Audit any custom code calling Site.publishDestAlias/writeDestAlias to never pass an empty path."],"exampleFix":"+++\n# before\naliases = [\"\", \"/posts/old-url/\"]\n# after\naliases = [\"/posts/old-url/\"]\n+++","handlingStrategy":"validation","validationCode":"func validAliases(as []string) error {\n    for _, a := range as {\n        if strings.TrimSpace(a) == \"\" { return fmt.Errorf(\"empty alias\") }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Strip empty entries when generating front matter programmatically.","Lint front matter aliases with a YAML/TOML validator before commit.","Never pass empty string to publishDestAlias/writeDestAlias."],"tags":["alias","front-matter","validation","hugolib"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}