AngleSharp / AngleSharp.Css

:angel: Library to enable support for cascading stylesheets in AngleSharp.
https://anglesharp.github.io
MIT License
72 stars 34 forks source link

ParseStyleSheetAsync throws NPE on empty string #42

Closed Fraaankes closed 4 years ago

Fraaankes commented 4 years ago

Bug Report

Prerequisites

For more information, see the CONTRIBUTING guide.

Description

Calling CssParser.ParseStyleSheetAsync("") throws a System.NullReferenceException.

Steps to Reproduce

Code:

class Program
    {
        static async Task Main(string[] args)
        {
            var parser = new CssParser();
            var s = await parser.ParseStyleSheetAsync("");

            Console.WriteLine(s);
        }
    }

Stacktrace: Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object. at AngleSharp.Text.TextSource.DetectByteOrderMarkAsync(CancellationToken cancellationToken) at AngleSharp.Text.TextSource.PrefetchAllAsync(CancellationToken cancellationToken) at AngleSharp.Css.Parser.CssParser.ParseStyleSheetAsync(String content, CancellationToken cancelToken)

Expected behavior: [What you expected to happen] To behave like the non-async version which correctly parses the empty string and returns an empty stylesheet.

Environment details: [OS, .NET Runtime, ...] Windows 10 .NET Core 3.0.100

FlorianRappl commented 4 years ago

Thanks for the report. I'll look into it!

FlorianRappl commented 4 years ago

Landed in devel and the preview on NuGet.