Prepare regexps on compile time (#1327)

This commit is contained in:
Yury Gargay
2023-11-27 13:01:00 +01:00
committed by GitHub
parent 0ca06b566a
commit 63d211c698
7 changed files with 24 additions and 26 deletions

View File

@@ -86,6 +86,8 @@ func (s SimpleRecord) Len() uint16 {
}
}
var invalidHostMatcher = regexp.MustCompile(invalidHostLabel)
// GetParsedDomainLabel returns a domain label with max 59 characters,
// parsed for old Hosts.txt requirements, and converted to ASCII and lowercase
func GetParsedDomainLabel(name string) (string, error) {
@@ -99,8 +101,6 @@ func GetParsedDomainLabel(name string) (string, error) {
return "", fmt.Errorf("unable to convert host label to ASCII, error: %v", err)
}
invalidHostMatcher := regexp.MustCompile(invalidHostLabel)
validHost := strings.ToLower(invalidHostMatcher.ReplaceAllString(ascii, "-"))
if len(validHost) > 58 {
validHost = validHost[:59]