Taritsyn / WebMarkupMin

The Web Markup Minifier (abbreviated WebMarkupMin) - a .NET library that contains a set of markup minifiers. The objective of this project is to improve the performance of web applications by reducing the size of HTML, XHTML and XML code.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HtmlMinifier.Minify throws InvalidOperationException

Metalnem opened this issue · comments

HtmlMinifier.Minify sometimes throws InvalidOperationException. Here's the full program to reproduce it:

namespace WebMarkupMin.Core.Run
{
  public class Program
  {
    public static void Main(string[] args)
    {
      string html = @"<head><td>m<head>l><html><body><h1>h1</h1><p>p</p></body></html>";
      new HtmlMinifier().Minify(html);
    }
  }
}

The full stack trace:

Exception has occurred: CLR/System.InvalidOperationException
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Linq.dll: 'Sequence contains more than one matching element'
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
   at WebMarkupMin.Core.Parsers.HtmlParser.ParseStartTag(String tagName, String tagNameInLowercase, IList`1 attributes, Boolean isEmptyTag)
   at WebMarkupMin.Core.Parsers.HtmlParser.ProcessStartTag()
   at WebMarkupMin.Core.Parsers.HtmlParser.Parse(String content)
   at WebMarkupMin.Core.GenericHtmlMinifier.Minify(String content, String fileContext, Encoding encoding, Boolean generateStatistics)
   at WebMarkupMin.Core.HtmlMinifier.Minify(String content)

I'm using .NET Core 2.1 and the latest NuGet version of WebMarkupMin.Core (2.5.5).

Found via SharpFuzz.

Hello, Nemanja!

This error is fixed in version 2.5.6. Thanks for information!