{"record":{"id":"20ed961a6eae6a11","repo":"gohugoio/hugo","slug":"failed-to-split-baseurl-hostport-w","errorCode":null,"errorMessage":"failed to split baseURL hostport: %w","messagePattern":"failed to split baseURL hostport: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/server.go","lineNumber":838,"sourceCode":"\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t}\n\n\tif useLocalhost {\n\t\tif certsSet {\n\t\t\tu.Scheme = \"https\"\n\t\t} else if u.Scheme == \"https\" {\n\t\t\tu.Scheme = \"http\"\n\t\t}\n\t\tu.Host = \"localhost\"\n\t}\n\n\tif c.serverAppend {\n\t\tif strings.Contains(u.Host, \":\") {\n\t\t\tu.Host, _, err = net.SplitHostPort(u.Host)\n\t\t\tif err != nil {\n\t\t\t\treturn \"\", fmt.Errorf(\"failed to split baseURL hostport: %w\", err)\n\t\t\t}\n\t\t}\n\t\tu.Host += fmt.Sprintf(\":%d\", port)\n\t}\n\n\treturn u.String(), nil\n}\n\nfunc (c *serverCommand) partialReRender(urls ...string) (err error) {\n\tdefer func() {\n\t\tc.errState.setWasErr(false)\n\t}()\n\tvisited := types.NewEvictingQueue[string](len(urls))\n\tfor _, url := range urls {\n\t\tvisited.Add(url)\n\t}\n\n\tvar h *hugolib.HugoSites","sourceCodeStart":820,"sourceCodeEnd":856,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/commands/server.go#L820-L856","documentation":"While massaging the baseURL in `fixURL`, when `--appendPort` is enabled and the host already contains a colon, Hugo calls `net.SplitHostPort` to strip any existing port before re-appending the server port. This wraps a `SplitHostPort` failure, indicating the host segment is malformed (e.g. too many colons without brackets).","triggerScenarios":"Fires when `serverAppend` is true, the parsed baseURL host contains `:`, and `net.SplitHostPort(u.Host)` errors — for example an IPv6 address without brackets, or a host like `host:port:extra`.","commonSituations":"Setting a `baseURL` to an IPv6 literal without square brackets (`http://::1/`); a malformed `--baseURL` with multiple colons; a config migrated from another tool that produced a non-RFC host string.","solutions":["Use bracketed IPv6 in the baseURL, e.g. `http://[::1]:1313/`.","Simplify the baseURL to a clean host without an embedded port (Hugo appends the server port itself).","If you truly need a fixed port in baseURL, set `appendPort = false` in `hugo.toml`."],"exampleFix":"// before\nbaseURL = \"http://::1/\"\n// after\nbaseURL = \"http://[::1]/\"","handlingStrategy":"validation","validationCode":"import \"net/url\"\nimport \"net\"\nfunc validateBaseURLHost(rawBaseURL string, appendPort bool) error {\n  if !appendPort { return nil }\n  u, err := url.Parse(rawBaseURL)\n  if err != nil { return err }\n  if strings.Contains(u.Host, \":\") {\n    if _, _, err := net.SplitHostPort(u.Host); err != nil {\n      return fmt.Errorf(\"malformed host %q: %w\", u.Host, err)\n    }\n  }\n  return nil\n}","typeGuard":"null","tryCatchPattern":"// If the baseURL host can't be split, fall back to a clean host\n// without an embedded port and let Hugo append its server port.\nif _, _, err := net.SplitHostPort(u.Host); err != nil {\n  // strip the port portion or use a bracketed IPv6 form\n}","preventionTips":["Bracket IPv6 literals in baseURL: `http://[::1]/`.","Don't embed a custom port in baseURL when `appendPort` is true (Hugo manages the port).","Set `appendPort = false` if you need to pin a port inside baseURL."],"tags":["hugo","server","url","network"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}