From c500345d16586e5a7c917611d52261beac2ac501 Mon Sep 17 00:00:00 2001 From: Andrey Meshkov Date: Mon, 26 Nov 2018 14:09:43 +0300 Subject: [PATCH] Fix #460 --- dnsfilter/dnsfilter_test.go | 9 +++++++++ dnsfilter/rule_to_regexp.go | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/dnsfilter/dnsfilter_test.go b/dnsfilter/dnsfilter_test.go index f186ecce..39b33a44 100644 --- a/dnsfilter/dnsfilter_test.go +++ b/dnsfilter/dnsfilter_test.go @@ -474,6 +474,15 @@ func TestDnsFilterWhitelist(t *testing.T) { d.checkMatch(t, "example.org") d.checkMatchEmpty(t, "test.example.org") d.checkMatchEmpty(t, "test.test.example.org") + + d.checkAddRule(t, "||googleadapis.l.google.com^|") + d.checkMatch(t, "googleadapis.l.google.com") + d.checkMatch(t, "test.googleadapis.l.google.com") + + d.checkAddRule(t, "@@||googleadapis.l.google.com|") + d.checkMatchEmpty(t, "googleadapis.l.google.com") + d.checkMatchEmpty(t, "test.googleadapis.l.google.com") + } func TestDnsFilterImportant(t *testing.T) { diff --git a/dnsfilter/rule_to_regexp.go b/dnsfilter/rule_to_regexp.go index 79c0320d..41d55e30 100644 --- a/dnsfilter/rule_to_regexp.go +++ b/dnsfilter/rule_to_regexp.go @@ -72,6 +72,11 @@ func getSuffix(rule string) (bool, string) { // last char was checked, eat it rule = rule[:len(rule)-1] + // it might also end with ^| + if rule[len(rule)-1] == '^' { + rule = rule[:len(rule)-1] + } + // check that it doesn't have any special characters inside for _, r := range rule { switch r {