From 8a940bd1cd3b788d1ec336ef191232c66b502051 Mon Sep 17 00:00:00 2001 From: krashanoff Date: Fri, 3 Jul 2020 00:33:32 -0700 Subject: [PATCH] Remove unnecessary export. Clarify comments. Closes #972 --- lib/options.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/options.go b/lib/options.go index 09e45556a4b1..44c92dc275e7 100644 --- a/lib/options.go +++ b/lib/options.go @@ -198,15 +198,14 @@ type HostnameTrie struct { terminal bool // end of a valid match } -// describes a valid hostname pattern to block by. Global var to avoid -// compilation penalty each call to ValidHostname. -var validHostnamePattern *regexp.Regexp = regexp.MustCompile("^\\*?(\\pL|[0-9\\.])*") - -// ValidHostname returns whether the provided hostname pattern -// has an optional wildcard at the start, and is composed entirely -// of letters, numbers, or '.'s. -func ValidHostname(s string) error { - if len(validHostnamePattern.FindString(s)) != len(s) { +// Regex description of hostname pattern to enforce blocks by. Global var +// to avoid compilation penalty at runtime. +// Matches against strings composed entirely of letters, numbers, or '.'s +// with an optional wildcard at the start. +var legalHostnamePattern *regexp.Regexp = regexp.MustCompile("^\\*?(\\pL|[0-9\\.])*") + +func legalHostname(s string) error { + if len(legalHostnamePattern.FindString(s)) != len(s) { return fmt.Errorf("invalid hostname pattern %s", s) } return nil @@ -238,13 +237,14 @@ func (t *HostnameTrie) UnmarshalText(b []byte) error { return nil } -// Insert a string into the given HostnameTrie. +// Insert a hostname pattern into the given HostnameTrie. Returns an error +// if hostname pattern is illegal. func (t *HostnameTrie) Insert(s string) error { if len(s) == 0 { return nil } - if err := ValidHostname(s); err != nil { + if err := legalHostname(s); err != nil { return err } @@ -272,6 +272,7 @@ func (t *HostnameTrie) Contains(s string) (bool, string) { return false, "" } +// recursively traverse HostnameTrie children searching for a match. func (t *HostnameTrie) childContains(s string, match string) (bool, string) { if len(s) == 0 { return false, ""