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

HtmlMinifier.Minify throws InvalidOperationException #77

Metalnem opened this issue Jan 21, 2019 · 1 comment

HtmlMinifier.Minify throws InvalidOperationException #77

Metalnem opened this issue Jan 21, 2019 · 1 comment


Copy link

@Metalnem Metalnem commented Jan 21, 2019

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.


This comment has been minimized.

Copy link

@Taritsyn Taritsyn commented Mar 7, 2019

Hello, Nemanja!

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

@Taritsyn Taritsyn closed this Mar 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.