@@ -198,15 +198,14 @@ type HostnameTrie struct {
198
198
terminal bool // end of a valid match
199
199
}
200
200
201
- // describes a valid hostname pattern to block by. Global var to avoid
202
- // compilation penalty each call to ValidHostname.
203
- var validHostnamePattern * regexp.Regexp = regexp .MustCompile ("^\\ *?(\\ pL|[0-9\\ .])*" )
204
-
205
- // ValidHostname returns whether the provided hostname pattern
206
- // has an optional wildcard at the start, and is composed entirely
207
- // of letters, numbers, or '.'s.
208
- func ValidHostname (s string ) error {
209
- if len (validHostnamePattern .FindString (s )) != len (s ) {
201
+ // Regex description of hostname pattern to enforce blocks by. Global var
202
+ // to avoid compilation penalty at runtime.
203
+ // Matches against strings composed entirely of letters, numbers, or '.'s
204
+ // with an optional wildcard at the start.
205
+ var legalHostnamePattern * regexp.Regexp = regexp .MustCompile ("^\\ *?(\\ pL|[0-9\\ .])*" )
206
+
207
+ func legalHostname (s string ) error {
208
+ if len (legalHostnamePattern .FindString (s )) != len (s ) {
210
209
return fmt .Errorf ("invalid hostname pattern %s" , s )
211
210
}
212
211
return nil
@@ -238,13 +237,14 @@ func (t *HostnameTrie) UnmarshalText(b []byte) error {
238
237
return nil
239
238
}
240
239
241
- // Insert a string into the given HostnameTrie.
240
+ // Insert a hostname pattern into the given HostnameTrie. Returns an error
241
+ // if hostname pattern is illegal.
242
242
func (t * HostnameTrie ) Insert (s string ) error {
243
243
if len (s ) == 0 {
244
244
return nil
245
245
}
246
246
247
- if err := ValidHostname (s ); err != nil {
247
+ if err := legalHostname (s ); err != nil {
248
248
return err
249
249
}
250
250
@@ -272,6 +272,7 @@ func (t *HostnameTrie) Contains(s string) (bool, string) {
272
272
return false , ""
273
273
}
274
274
275
+ // recursively traverse HostnameTrie children searching for a match.
275
276
func (t * HostnameTrie ) childContains (s string , match string ) (bool , string ) {
276
277
if len (s ) == 0 {
277
278
return false , ""
0 commit comments