MCPcopy Index your code
hub / github.com/foxcpp/maddy / ValidDomain

Function ValidDomain

framework/address/validation.go:113–138  ·  view source on GitHub ↗

ValidDomain checks whether the specified string is a valid DNS domain.

(domain string)

Source from the content-addressed store, hash-verified

111
112// ValidDomain checks whether the specified string is a valid DNS domain.
113func ValidDomain(domain string) bool {
114 if len(domain) > 255 || len(domain) == 0 {
115 return false
116 }
117 if strings.HasPrefix(domain, ".") {
118 return false
119 }
120 if strings.Contains(domain, "..") {
121 return false
122 }
123
124 // Length checks are to be applied to A-labels form.
125 // maddy uses U-labels representation across the code (for lookups, etc).
126 domainASCII, err := idna.ToASCII(domain)
127 if err != nil {
128 return false
129 }
130 labels := strings.Split(domainASCII, ".")
131 for _, label := range labels {
132 if len(label) > 64 {
133 return false
134 }
135 }
136
137 return true
138}

Callers 4

TestValidDomainFunction · 0.92
ConfigureMethod · 0.92
validMatchRuleFunction · 0.92
ValidFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestValidDomainFunction · 0.74