{"id":"eea7447685490db8","repo":"gofiber/fiber","slug":"domain-pattern-s-contains-empty-parameter-name","errorCode":null,"errorMessage":"Domain pattern '%s' contains empty parameter name at position %d","messagePattern":"Domain pattern '(.+?)' contains empty parameter name at position (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"domain.go","lineNumber":94,"sourceCode":"\t\tpanic(fmt.Sprintf(\"Domain pattern '%s' has %d parts, which exceeds the maximum of %d\",\n\t\t\tpattern, len(parts), maxDomainParts))\n\t}\n\n\tm := domainMatcher{\n\t\tparts:    make([]string, len(parts)),\n\t\tnumParts: len(parts),\n\t}\n\n\tfor i, part := range parts {\n\t\t// Validate no empty labels (e.g., \"example..com\" is invalid)\n\t\tif part == \"\" {\n\t\t\tpanic(fmt.Sprintf(\"Domain pattern '%s' contains empty label at position %d\", pattern, i))\n\t\t}\n\n\t\tif part[0] == ':' {\n\t\t\t// Validate parameter name is not empty\n\t\t\tif len(part) == 1 {\n\t\t\t\tpanic(fmt.Sprintf(\"Domain pattern '%s' contains empty parameter name at position %d\", pattern, i))\n\t\t\t}\n\t\t\tparamName := part[1:]\n\t\t\t// Validate parameter name contains only ASCII-safe characters (a-z, A-Z, 0-9, underscore, hyphen).\n\t\t\t// Using explicit ASCII ranges rather than unicode.IsLetter/IsDigit to reject non-ASCII\n\t\t\t// characters that are invalid in DNS names.\n\t\t\tfor _, ch := range paramName {\n\t\t\t\tif !isASCIIAlphanumeric(ch) && ch != '_' && ch != '-' {\n\t\t\t\t\tpanic(fmt.Sprintf(\"Domain pattern '%s' contains invalid parameter name '%s' with character '%c'\", pattern, paramName, ch))\n\t\t\t\t}\n\t\t\t}\n\t\t\tm.paramIdx = append(m.paramIdx, i)\n\t\t\tm.paramNames = append(m.paramNames, paramName) // preserve original case\n\t\t\tm.parts[i] = part                              // keep \":param\" marker for matching\n\t\t} else {\n\t\t\t// Only lowercase constant labels (RFC 4343)\n\t\t\t// Enforce RFC 1035 per-label length limit (63 characters)\n\t\t\tif len(part) > 63 {\n\t\t\t\tpanic(fmt.Sprintf(\"Domain pattern '%s' has label '%s' exceeding RFC 1035 limit of 63 characters (%d chars)\",","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/domain.go#L76-L112","documentation":"Panics from domain.go:94 when a domain parameter is just the colon marker with no name, e.g. a label equal to \":\". Parameter labels must be \":name\"; a bare \":\" has no parameter name to bind and would break DomainParam lookups.","triggerScenarios":"app.Domain(\":.example.com\") - a label that is only \":\". Also app.Domain(\"example.com:\") is different (a label ending in colon is treated as constant and fails the character check, not this one); this specific panic is the lone-colon label.","commonSituations":"Templating that emits \":\" + name where name is empty; refactoring parameter naming that left a stray colon; user input used as a parameter name that was blank.","solutions":["Give every parameter a name: app.Domain(\":tenant.example.com\").","Validate that each \":\"-prefixed label has length > 1 before calling Domain().","Default empty parameter names to a concrete name like \"sub\"."],"exampleFix":"// before\nname := params[\"name\"] // \"\"\napp.Domain(\":\" + name + \".example.com\").Get(\"/\", h)\n\n// after\nname := params[\"name\"]\nif name == \"\" {\n    name = \"tenant\"\n}\napp.Domain(\":\" + name + \".example.com\").Get(\"/\", h)","handlingStrategy":"validation","validationCode":"for _, label := range strings.Split(pattern, \".\") {\n    if label == \":\" {\n        return fmt.Errorf(\"domain parameter missing name\")\n    }\n}\napp.Domain(pattern).Get(\"/\", h)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never template a ':' without a guaranteed non-empty name.","Default blank parameter names to a safe constant.","Validate ':' labels have length > 1."],"tags":["routing","domain","validation","parameter","panic"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}