Skip to content

Commit

Permalink
Fix missing comments, upgrade deps
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnikEmpire committed Dec 10, 2018
1 parent 8f49040 commit 42400c9
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 39 deletions.
12 changes: 6 additions & 6 deletions DistillNET/DistillNET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
<RepositoryUrl>https://github.com/TechnikEmpire/DistillNET</RepositoryUrl>
<Description>DistillNET is a library for matching and filtering HTTP requests URLs using the Adblock Plus Filter format.</Description>
<Copyright>Copyright © 2017 - 2018 Jesse Nicholson</Copyright>
<Version>1.6.2</Version>
<Version>1.6.3</Version>
<Authors>Jesse Nicholson</Authors>
<Company>Technik Empire</Company>
<PackageTags>DistillNET Adblock AdblockPlus Adblock-Plus URL-Filter URL-Filtering Content-Filter Filter</PackageTags>
<PackageReleaseNotes>Fixes an issue where cache is not built on an instance where no rules are ever loaded.</PackageReleaseNotes>
<AssemblyVersion>1.6.2.0</AssemblyVersion>
<FileVersion>1.6.2.0</FileVersion>
<PackageReleaseNotes>Upgrades dependencies to latest version.</PackageReleaseNotes>
<AssemblyVersion>1.6.3.0</AssemblyVersion>
<FileVersion>1.6.3.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand All @@ -27,8 +27,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Data.SQLite" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.1.0" />
<PackageReference Include="Microsoft.Data.SQLite" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.2.0" />
</ItemGroup>

</Project>
19 changes: 15 additions & 4 deletions DistillNET/DistillNET/AbpFormatRuleParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using DistillNET.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;

namespace DistillNET
{
Expand Down Expand Up @@ -94,6 +95,7 @@ int IEqualityComparer<string>.GetHashCode(string obj)
{ "~elemhide", UrlFilter.UrlFilterOptions.ExceptElemHide },
{ "other", UrlFilter.UrlFilterOptions.Other },
{ "~other", UrlFilter.UrlFilterOptions.ExceptOther },
#pragma warning disable CS0618 // Type or member is obsolete
{ "media", UrlFilter.UrlFilterOptions.Media },
{ "~media", UrlFilter.UrlFilterOptions.ExceptMedia },
{ "font", UrlFilter.UrlFilterOptions.Font },
Expand All @@ -105,6 +107,7 @@ int IEqualityComparer<string>.GetHashCode(string obj)
{ "generichide", UrlFilter.UrlFilterOptions.GenericHide },
{ "genericblock", UrlFilter.UrlFilterOptions.GenericBlock },
{ "ping", UrlFilter.UrlFilterOptions.Ping }
#pragma warning restore CS0618 // Type or member is obsolete
};

/// <summary>
Expand All @@ -114,8 +117,13 @@ int IEqualityComparer<string>.GetHashCode(string obj)
private static readonly char[] s_anchoredEndIndicators = new[] { '/', ':', '?', '=', '&', '*', '^' };

/// <summary>
/// Constructs a new instance.
/// </summary>
/// <param name="rule">
/// The rule string.
/// </param>
/// <param name="categoryId">
/// The category ID to assign to this rule.
/// </param>
/// <returns>
/// </returns>
Expand Down Expand Up @@ -169,7 +177,7 @@ public Filter ParseAbpFormattedRule(string rule, short categoryId)
{
return ParseCssSelector(rule, cssSelectorStart, isException, categoryId);
}
catch(ArgumentOutOfRangeException e)
catch (ArgumentOutOfRangeException)
{
throw new ArgumentException("Out of range exception while parsing CSS selector rule. Rule must be malformed.", nameof(rule));
}
Expand All @@ -179,7 +187,7 @@ public Filter ParseAbpFormattedRule(string rule, short categoryId)
{
return ParseUrlFilter(rule, optionsStart, hasOptions, isException, categoryId);
}
catch(ArgumentOutOfRangeException e)
catch (ArgumentOutOfRangeException)
{
throw new ArgumentException("Out of range exception while parsing filter rule. Rule must be malformed.", nameof(rule));
}
Expand All @@ -198,22 +206,25 @@ public Filter ParseAbpFormattedRule(string rule, short categoryId)
/// Whether or not this rule is an exception rule. It is obviously assumed that this has been
/// predetermined externally and this will not be determined internally.
/// </param>
/// <param name="categoryId">
/// The category ID to assign to this rule.
/// </param>
/// <returns>
/// A css selector filtering class instance built from the parsed rule.
/// </returns>
private Filter ParseCssSelector(string rule, int selectorStartOffset, bool isException, short categoryId)
{
var originalRuleCopy = rule;

string[] applicableDomains = null;
List<string> applicableDomains = null;

if(selectorStartOffset > 0)
{
// Whenever the start of the selector rule is not the start of the string, this
// indicates that it's a domain-specific CSS selector rule. As such, one or more
// domains, separated by a comma character, will preceed the actual CSS selector
// rule.
applicableDomains = rule.Substring(0, selectorStartOffset).Split(s_optionsDelim, StringSplitOptions.None);
applicableDomains = rule.Substring(0, selectorStartOffset).Split(s_optionsDelim, StringSplitOptions.None).ToList();
}

// If it's an exception, we need to cut off three characters from the start of the CSS
Expand Down
14 changes: 9 additions & 5 deletions DistillNET/DistillNET/FilterDbCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -550,14 +550,15 @@ private List<string> GetAllPossibleSubdomains(string inputDomain)
return retVal;
}

public IEnumerable<Filter> GetFiltersForRequest(Uri requestString, string referer = "")
{
return null;
}

#region IDisposable Support
private bool disposedValue = false; // To detect redundant calls

/// <summary>
/// Disposes the object.
/// </summary>
/// <param name="disposing">
/// Disposing val.
/// </param>
protected virtual void Dispose(bool disposing)
{
if(!disposedValue)
Expand Down Expand Up @@ -585,6 +586,9 @@ protected virtual void Dispose(bool disposing)
// }

// This code added to correctly implement the disposable pattern.
/// <summary>
/// Disposes the object.
/// </summary>
public void Dispose()
{
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
Expand Down
62 changes: 50 additions & 12 deletions DistillNET/DistillNET/HtmlFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,56 @@
*/

using System;
using System.Diagnostics;
using System.Collections.Generic;

namespace DistillNET
{
/// <summary>
/// The HtmlFilter is a class that represents a CSS selector that can be removed or whitelisted
/// in source HTML.
/// </summary>
public class HtmlFilter : Filter
{
/// <summary>
/// Gets an array of all domains that this CSS selector rule applies to. In the event that
/// this array is empty, the rule applies globally, to all domains.
/// Gets a list of all referers that this HTML filter rule applies to. In the event that this
/// array is empty, the referer field on requests will not be checked.
/// </summary>
public string[] ApplicableDomains
public List<string> ApplicableReferers
{
get;
private set;
} = new string[0];
}

/// <summary>
/// Gets a list of all referers that this HTML filter rule applies to. In the event that this
/// array is empty, the referer field on requests will not be checked.
/// </summary>
public List<string> ExceptReferers
{
get;
private set;
}

/// <summary>
/// Gets a list of all domains that this HTML filter rule applies to. In the event that this
/// array is empty, the rule applies globally, to all domains.
/// </summary>
public List<string> ApplicableDomains
{
get;
private set;
}

/// <summary>
/// Gets a list of all domains that this HTML filter should not be applied to. In the event
/// that this array is empty, the rule applies either globally, or exclusively to the list of
/// applicable domains, if that property is not empty.
/// </summary>
public List<string> ExceptionDomains
{
get;
private set;
}

/// <summary>
/// Gets the raw CSS selector rule string.
Expand Down Expand Up @@ -49,14 +84,17 @@ public string CssSelector
/// Whether or not this CSS selector rule is an exception. Exception rules protect matching
/// content from being filtered out.
/// </param>
/// <param name="categoryId">
/// The category ID to assign to this rule.
/// </param>
/// <exception cref="ArgumentException">
/// If compiled with TE_FILTERING_VERIFY_RULE_DATA, the cssSelector parameter will undergo
/// checks to ensure that it is not null, empty or whitespace. If these checks are performed
/// and any of those conditions is true, the constructor will throw this exception.
/// </exception>
internal HtmlFilter(string originalRule, string[] applicableDomains, string cssSelector, bool isException, short categoryId) : base(originalRule, isException, categoryId)
internal HtmlFilter(string originalRule, List<string> applicableDomains, string cssSelector, bool isException, short categoryId) : base(originalRule, isException, categoryId)
{
if(applicableDomains != null && applicableDomains.Length > 0)
if (applicableDomains != null && applicableDomains.Count > 0)
{
ApplicableDomains = applicableDomains;
}
Expand All @@ -72,13 +110,13 @@ internal HtmlFilter(string originalRule, string[] applicableDomains, string cssS
CssSelector = cssSelector;
}

/// <summary>
/// Removes verbose data from the constructed instance.
/// </summary>
public override void TrimExcessData()
{
if(this.ApplicableDomains != null)
{
Array.Clear(this.ApplicableDomains, 0, this.ApplicableDomains.Length);
this.ApplicableDomains = new string[0];
}
ApplicableDomains.Clear();
ExceptionDomains.Clear();

OriginalRule = string.Empty;
}
Expand Down
Loading

0 comments on commit 42400c9

Please sign in to comment.