You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because Find returns pointers, it allows the user of the library to modify default definitions. It's true that it shouldn't be done to begin with, but it would be good to protect against it.
// Find and returns the most appropriate rule for the domain name.
func (l *List) Find(name string, options *FindOptions) *Rule {
if options == nil {
options = DefaultFindOptions
}
part := name
for {
rule, ok := l.rules[part]
if ok && rule.Match(name) && !(options.IgnorePrivate && rule.Private) {
return rule
}
i := strings.IndexRune(part, '.')
if i < 0 {
return options.DefaultRule
}
part = part[i+1:]
}
return nil
}
We can rewrite it as such:
// Find and returns the most appropriate rule for the domain name.
func (l *List) Find(name string, options *FindOptions) *Rule {
if options == nil {
options = DefaultFindOptions
}
part := name
var out Rule
for {
rule, ok := l.rules[part]
if ok && rule.Match(name) && !(options.IgnorePrivate && rule.Private) {
out = *rule
return &out
}
i := strings.IndexRune(part, '.')
if i < 0 {
out = *options.DefaultRule
return &out
}
part = part[i+1:]
}
return nil
}
The text was updated successfully, but these errors were encountered:
Because Find returns pointers, it allows the user of the library to modify default definitions. It's true that it shouldn't be done to begin with, but it would be good to protect against it.
We can rewrite it as such:
The text was updated successfully, but these errors were encountered: