package config import ( "strings" "unicode" "unicode/utf8" ) const ( siteNameMaxBytes = 64 reasonSiteName = "must be at most 64 bytes of UTF-8 text with a visible character and no control characters (the display-name rule, ยง3.8)" ) func siteNameValid(value string) bool { if value == "" || len(value) > siteNameMaxBytes || !utf8.ValidString(value) { return false } for _, r := range value { if unicode.IsControl(r) { return false } } return strings.IndexFunc(value, siteNameVisible) >= 0 } func siteNameVisible(r rune) bool { return !unicode.IsSpace(r) && !unicode.In(r, unicode.Cf, unicode.Variation_Selector, unicode.Other_Default_Ignorable_Code_Point) } func (v *validator) siteName(value string) string { if !v.idx.has("server.site_name") { return "" } switch { case value == "": v.add("server.site_name", reasonEmpty) case !siteNameValid(value): v.add("server.site_name", reasonSiteName) } return value }