{"id":"a4bbfe77b1664a2e","repo":"gofiber/fiber","slug":"domain-pattern-s-contains-invalid-character-c","errorCode":null,"errorMessage":"Domain pattern '%s' contains invalid character '%c' in label '%s'","messagePattern":"Domain pattern '(.+?)' contains invalid character '%c' in label '(.+?)'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"domain.go","lineNumber":119,"sourceCode":"\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)\",\n\t\t\t\t\tpattern, part, len(part)))\n\t\t\t}\n\t\t\t// Validate label contains only valid ASCII domain characters (a-z, 0-9, hyphen).\n\t\t\tnormalized := utilsstrings.ToLower(part)\n\t\t\tfor _, ch := range normalized {\n\t\t\t\tif !isASCIIAlphanumeric(ch) && ch != '-' {\n\t\t\t\t\tpanic(fmt.Sprintf(\"Domain pattern '%s' contains invalid character '%c' in label '%s'\", pattern, ch, part))\n\t\t\t\t}\n\t\t\t}\n\t\t\tm.parts[i] = normalized\n\t\t}\n\t}\n\n\t// Check if the domain pattern has too many parameters\n\tif len(m.paramNames) > maxParams {\n\t\tpanic(fmt.Sprintf(\"Domain pattern '%s' has %d parameters, which exceeds the maximum of %d\",\n\t\t\tpattern, len(m.paramNames), maxParams))\n\t}\n\n\treturn m\n}\n\n// match checks if a hostname matches the domain pattern.\n// It returns true if matched and a slice of parameter values (parallel to paramNames).\n// Uses a stack-allocated buffer to avoid heap allocation for typical domain names.","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/domain.go#L101-L137","documentation":"Panics from domain.go:119 when a constant label (after lowercasing per RFC 4343) contains a character other than ASCII a-z, 0-9, or hyphen. These are the only characters legal in DNS hostnames, so any other byte (underscore, wildcard '*', slash, unicode, etc.) is rejected.","triggerScenarios":"app.Domain(\"sub_domain.example.com\") panics on '_'; app.Domain(\"*.example.com\") panics on '*'; app.Domain(\"cafe.example.com\") with a non-ASCII 'e' panics. Wildcards are not supported as constant labels.","commonSituations":"Trying to use wildcard subdomains via '*' (fiber's domain router is pattern-based on labels, not glob); underscores from service-discovery names; pasting internationalized names without IDNA punycode encoding.","solutions":["Use only letters, digits, and hyphens in constant labels.","Use a parameter label (\":sub.example.com\") instead of '*' to capture arbitrary subdomains.","Punycode-encode IDN labels before registering them."],"exampleFix":"// before\napp.Domain(\"*.example.com\").Get(\"/\", h) // '*' invalid\n\n// after - capture any single subdomain label\napp.Domain(\":sub.example.com\").Get(\"/\", h)\n// then read fiber.DomainParam(c, \"sub\")","handlingStrategy":"validation","validationCode":"for _, label := range strings.Split(pattern, \".\") {\n    if strings.HasPrefix(label, \":\") {\n        continue\n    }\n    lower := strings.ToLower(label)\n    for _, ch := range lower {\n        if !((ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9') || ch == '-') {\n            return fmt.Errorf(\"invalid char %q in label %s\", ch, label)\n        }\n    }\n}\napp.Domain(pattern).Get(\"/\", h)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only [a-z0-9-] in constant labels.","Use ':param' labels instead of '*' for wildcard subdomains.","Punycode-encode IDN labels before registering."],"tags":["routing","domain","validation","rfc-1035","ascii","panic"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}