diff --git a/internal/dnsfilter/rewrites.go b/internal/dnsfilter/rewrites.go index 146be60a..5aae925a 100644 --- a/internal/dnsfilter/rewrites.go +++ b/internal/dnsfilter/rewrites.go @@ -122,21 +122,27 @@ func findRewrites(a []RewriteEntry, host string) []RewriteEntry { sort.Sort(rr) - isWC := isWildcard(rr[0].Domain) - if !isWC { - for i, r := range rr { - if isWildcard(r.Domain) { - rr = rr[:i] - break - } + for i, r := range rr { + if isWildcard(r.Domain) { + // Don't use rr[:0], because we need to return at least + // one item here. + rr = rr[:max(1, i)] + + break } - } else { - rr = rr[:1] } return rr } +func max(a, b int) int { + if a > b { + return a + } + + return b +} + func rewriteArrayDup(a []RewriteEntry) []RewriteEntry { a2 := make([]RewriteEntry, len(a)) copy(a2, a)