Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added strong name (signed) #17

Merged
merged 5 commits into from
May 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Web.HtmlSanitizer.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.3.1.0")]
[assembly: AssemblyFileVersion("1.3.1.0")]
68 changes: 42 additions & 26 deletions Web.HtmlSanitizer.Tests/Web.HtmlSanitizer.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props')" />
<Import Project="..\..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" />
<Import Project="..\packages\xunit.core.2.3.1\build\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.3.1\build\xunit.core.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -12,10 +11,11 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Vereyon.Web</RootNamespace>
<AssemblyName>Vereyon.Web.HtmlSanitizer.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -26,6 +26,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -34,31 +35,11 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="HtmlAgilityPack, Version=1.4.9.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
<HintPath>..\..\packages\HtmlAgilityPack.1.4.9\lib\Net40\HtmlAgilityPack.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="Vereyon.Web.HtmlSanitizer, Version=1.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Vereyon.Web.HtmlSanitizer.1.3.0\lib\net40\Vereyon.Web.HtmlSanitizer.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit, Version=1.9.2.1705, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AttributeCheckTests.cs" />
<Compile Include="CssWhitelistTests.cs" />
Expand All @@ -72,21 +53,56 @@
<Compile Include="UseCaseTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Web.HtmlSanitizer\Web.HtmlSanitizer.csproj">
<Project>{347a800b-bc19-4c3d-81b9-8e0d3fa839de}</Project>
<Name>Web.HtmlSanitizer</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Numerics" />
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
</Reference>
<Reference Include="xunit.assert, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.assert.2.3.1\lib\netstandard1.1\xunit.assert.dll</HintPath>
</Reference>
<Reference Include="xunit.core, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.core.2.3.1\lib\netstandard1.1\xunit.core.dll</HintPath>
</Reference>
<Reference Include="xunit.execution.dotnet, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.execution.2.3.1\lib\netstandard1.1\xunit.execution.dotnet.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\xunit.analyzers.0.8.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props'))" />
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props'))" />
<Error Condition="!Exists('..\packages\xunit.core.2.3.1\build\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.3.1\build\xunit.core.props'))" />
<Error Condition="!Exists('..\packages\xunit.core.2.3.1\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.3.1\build\xunit.core.targets'))" />
</Target>
<Import Project="..\packages\xunit.core.2.3.1\build\xunit.core.targets" Condition="Exists('..\packages\xunit.core.2.3.1\build\xunit.core.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ShowAllFiles</ProjectView>
<ProjectView>ProjectFiles</ProjectView>
</PropertyGroup>
</Project>
3 changes: 3 additions & 0 deletions Web.HtmlSanitizer.Tests/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>
41 changes: 38 additions & 3 deletions Web.HtmlSanitizer.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="HtmlAgilityPack" version="1.4.9" targetFramework="net40" />
<package id="Vereyon.Web.HtmlSanitizer" version="1.3.0" targetFramework="net40" />
<package id="xunit" version="1.9.2" targetFramework="net40" />
<package id="Microsoft.NETCore.Platforms" version="2.0.2" targetFramework="net45" />
<package id="NETStandard.Library" version="2.0.2" targetFramework="net45" />
<package id="System.Collections" version="4.3.0" targetFramework="net45" />
<package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net45" />
<package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="net45" />
<package id="System.Diagnostics.Tools" version="4.3.0" targetFramework="net45" />
<package id="System.Diagnostics.Tracing" version="4.3.0" targetFramework="net45" />
<package id="System.Globalization" version="4.3.0" targetFramework="net45" />
<package id="System.IO" version="4.3.0" targetFramework="net45" />
<package id="System.IO.Compression" version="4.3.0" targetFramework="net45" />
<package id="System.Linq" version="4.3.0" targetFramework="net45" />
<package id="System.Linq.Expressions" version="4.3.0" targetFramework="net45" />
<package id="System.Net.Http" version="4.3.3" targetFramework="net45" />
<package id="System.Net.Primitives" version="4.3.0" targetFramework="net45" />
<package id="System.ObjectModel" version="4.3.0" targetFramework="net45" />
<package id="System.Reflection" version="4.3.0" targetFramework="net45" />
<package id="System.Reflection.Extensions" version="4.3.0" targetFramework="net45" />
<package id="System.Reflection.Primitives" version="4.3.0" targetFramework="net45" />
<package id="System.Resources.ResourceManager" version="4.3.0" targetFramework="net45" />
<package id="System.Runtime" version="4.3.0" targetFramework="net45" />
<package id="System.Runtime.Extensions" version="4.3.0" targetFramework="net45" />
<package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="net45" />
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net45" />
<package id="System.Runtime.Numerics" version="4.3.0" targetFramework="net45" />
<package id="System.Text.Encoding" version="4.3.0" targetFramework="net45" />
<package id="System.Text.Encoding.Extensions" version="4.3.0" targetFramework="net45" />
<package id="System.Text.RegularExpressions" version="4.3.0" targetFramework="net45" />
<package id="System.Threading" version="4.3.0" targetFramework="net45" />
<package id="System.Threading.Tasks" version="4.3.0" targetFramework="net45" />
<package id="System.Xml.ReaderWriter" version="4.3.1" targetFramework="net45" />
<package id="System.Xml.XDocument" version="4.3.0" targetFramework="net45" />
<package id="xunit" version="2.3.1" targetFramework="net45" />
<package id="xunit.abstractions" version="2.0.1" targetFramework="net45" />
<package id="xunit.analyzers" version="0.8.0" targetFramework="net45" />
<package id="xunit.assert" version="2.3.1" targetFramework="net45" />
<package id="xunit.core" version="2.3.1" targetFramework="net45" />
<package id="xunit.extensibility.core" version="2.3.1" targetFramework="net45" />
<package id="xunit.extensibility.execution" version="2.3.1" targetFramework="net45" />
<package id="xunit.runner.visualstudio" version="2.3.1" targetFramework="net40" developmentDependency="true" />
</packages>
14 changes: 10 additions & 4 deletions Web.HtmlSanitizer/HtmlSanitizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public class HtmlSanitizer : IHtmlSanitizer

internal int Depth { get; set; }

public HtmlSanitizer()
/// <summary>Initializes a new instance of the <see cref="HtmlSanitizer"/> class.</summary>
public HtmlSanitizer()
{
WhiteListMode = true;
EncodeHtmlEntities = true;
Expand Down Expand Up @@ -163,7 +164,9 @@ public string Sanitize(string html)
return htmlDocument.DocumentNode.WriteTo();
}

public void SanitizeNode(HtmlNode node)
/// <summary>Sanitizes the node.</summary>
/// <param name="node">The node.</param>
public void SanitizeNode(HtmlNode node)
{

HtmlSanitizerTagRule rule;
Expand Down Expand Up @@ -397,7 +400,7 @@ private bool ApplyCssWhitelist(HtmlAttribute attribute)
{

// No empty or white space classes.
if (string.IsNullOrWhiteSpace(cssClass))
if (string.IsNullOrEmpty(cssClass?.Trim()))
continue;

// Only allowed classes.
Expand Down Expand Up @@ -476,7 +479,10 @@ public static HtmlSanitizer SimpleHtml5DocumentSanitizer()
}
}

public enum HtmlSanitizerCheckType
/// <summary>
/// Types of sanitizations.
/// </summary>
public enum HtmlSanitizerCheckType
{

/// <summary>
Expand Down
39 changes: 19 additions & 20 deletions Web.HtmlSanitizer/HtmlSanitizerFluentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ public static HtmlSanitizer AllowCss(this HtmlSanitizer sanitizer, params string
return sanitizer;
}

/// <summary>
/// White lists the specified space seperated CSS class names.
/// </summary>
/// <param name="className"></param>
/// <returns></returns>
public static HtmlSanitizer AllowCss(this HtmlSanitizer sanitizer, string classNames)
/// <summary>White lists the specified space seperated CSS class names.</summary>
/// <param name="sanitizer">The sanitizer.</param>
/// <param name="classNames">The class names.</param>
/// <returns></returns>
public static HtmlSanitizer AllowCss(this HtmlSanitizer sanitizer, string classNames)
{
return sanitizer.AllowCss(classNames.Split(' '));
}
Expand All @@ -53,14 +52,15 @@ public static HtmlSanitizerTagRule Tag(this HtmlSanitizer sanitizer, string tagN
return sanitizer.Tag(tagName, true);
}

/// <summary>
/// White lists the specified HTML tag, creating a rule for it which allows further specification of what is to be done
/// with the tag.
/// </summary>
/// <param name="sanitizer"></param>
/// <param name="tagName"></param>
/// <returns></returns>
public static HtmlSanitizerTagRule Tag(this HtmlSanitizer sanitizer, string tagName, bool replace)
/// <summary>
/// White lists the specified HTML tag, creating a rule for it which allows further specification of what is to be done
/// with the tag.
/// </summary>
/// <param name="sanitizer">The sanitizer.</param>
/// <param name="tagName">Name of the tag.</param>
/// <param name="replace">if set to <c>true</c> replace.</param>
/// <returns></returns>
public static HtmlSanitizerTagRule Tag(this HtmlSanitizer sanitizer, string tagName, bool replace)
{

HtmlSanitizerTagRule rule;
Expand Down Expand Up @@ -176,12 +176,11 @@ public static HtmlSanitizerTagRule RemoveEmpty(this HtmlSanitizerTagRule rule)
return rule;
}

/// <summary>
/// Specifies the operation to perform if this node does not have any attributes set.
/// </summary>
/// <param name="rule"></param>
/// <returns></returns>
public static HtmlSanitizerTagRule NoAttributes(this HtmlSanitizerTagRule rule, SanitizerOperation operation)
/// <summary>Specifies the operation to perform if this node does not have any attributes set.</summary>
/// <param name="rule">The rule.</param>
/// <param name="operation">The operation.</param>
/// <returns></returns>
public static HtmlSanitizerTagRule NoAttributes(this HtmlSanitizerTagRule rule, SanitizerOperation operation)
{
rule.NoAttributesOperation = operation;
return rule;
Expand Down
7 changes: 5 additions & 2 deletions Web.HtmlSanitizer/HtmlSanitizerTagRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ public class HtmlSanitizerTagRule
/// </summary>
public bool RemoveEmpty { get; set; }

public HtmlSanitizerTagRule(string tagName)
/// <summary>Initializes a new instance of the <see cref="HtmlSanitizerTagRule"/> class.</summary>
/// <param name="tagName">Name of the tag.</param>
public HtmlSanitizerTagRule(string tagName)
{
TagName = tagName;
Operation = SanitizerOperation.DoNothing;
Expand All @@ -69,7 +71,8 @@ public HtmlSanitizerTagRule(string tagName)
}
}

public enum SanitizerOperation
/// <summary></summary>
public enum SanitizerOperation
{
/// <summary>
/// Default operation. Does nothing.
Expand Down
36 changes: 0 additions & 36 deletions Web.HtmlSanitizer/Properties/AssemblyInfo.cs

This file was deleted.

14 changes: 11 additions & 3 deletions Web.HtmlSanitizer/RecursionGuard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ public class RecursionGuard : IDisposable

private HtmlSanitizer _sanitizer;

public RecursionGuard(HtmlSanitizer sanitizer)
/// <summary>Initializes a new instance of the <see cref="RecursionGuard"/> class.</summary>
/// <param name="sanitizer">The sanitizer.</param>
/// <exception cref="System.InvalidOperationException">Maximum recursion depth execeeded.</exception>
public RecursionGuard(HtmlSanitizer sanitizer)
{

_sanitizer = sanitizer;
Expand All @@ -23,11 +26,16 @@ public RecursionGuard(HtmlSanitizer sanitizer)
throw new InvalidOperationException("Maximum recursion depth execeeded.");
}

public void Dispose()
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
_sanitizer.Depth--;
}

public int Depth { get { return _sanitizer.Depth; } }
/// <summary>Gets the depth.</summary>
/// <value>The depth.</value>
public int Depth { get { return _sanitizer.Depth; } }
}
}
Loading