public void TestRegularDomainRule_WithoutException() { var parser = new AbpFormatRuleParser(); Filter filter = parser.ParseAbpFormattedRule("||testsite.com", 1); // Needs to be a URL filter. if (!(filter is UrlFilter)) { Assert.Fail(); } UrlFilter urlFilter = filter as UrlFilter; // is not exception to rule. Assert.IsFalse(urlFilter.IsException); // all subdomains should match as well. Assert.IsTrue(urlFilter.IsMatch(new Uri("https://subdomain.testsite.com"), null)); Assert.IsTrue(urlFilter.IsMatch(new Uri("https://testsite.com"), null)); Assert.IsTrue(urlFilter.IsMatch(new Uri("http://testsite.com"), null)); Assert.IsFalse(urlFilter.IsMatch(new Uri("http://does-not-match.com"), null)); }
static AdBlock() { var parser = new AbpFormatRuleParser(); var blacklist = Resources.adblock_blacklist.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); var compiledFilters = new List <Filter>(blacklist.Length); foreach (var entry in blacklist) { compiledFilters.Add(parser.ParseAbpFormattedRule(entry, 1)); } _adBlockFilters = new FilterDbCollection(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Guitarify\\AdBlock.db"), true, true); _adBlockFilters.ParseStoreRules(blacklist, 1); _adBlockFilters.FinalizeForRead(); }
public void TestRegularDomainRule_WithException() { var parser = new AbpFormatRuleParser(); Filter filter = parser.ParseAbpFormattedRule("@@||testsite.com", 1); // Needs to be a URL filter. if (!(filter is UrlFilter)) { Assert.Fail(); } UrlFilter urlFilter = filter as UrlFilter; // is exception to rule. Assert.IsTrue(urlFilter.IsException); // no need to test matching again for this one. }
public void TestUrlRule() { var parser = new AbpFormatRuleParser(); Filter filter = parser.ParseAbpFormattedRule("||reddit.com^r^nsfw", 1); // Needs to be a URL filter. if (!(filter is UrlFilter)) { Assert.Fail(); } UrlFilter urlFilter = filter as UrlFilter; // is exception to rule. Assert.IsFalse(urlFilter.IsException); Assert.IsTrue(urlFilter.IsMatch(new Uri("https://reddit.com/r/nsfw/posthere"), null)); Assert.IsFalse(urlFilter.IsMatch(new Uri("https://reddit.com/r/good"), null)); }