Skip to content

StyleCollectionExtensions.SortBySpecificity does not account for null selector. #52

Closed
@The-Nutty

Description

@The-Nutty

Bug Report

I have observed instances where ICssStyleRule.Selector is null. This causes StyleCollectionExtensions.SortBySpecificity to throw a null reference exception.

Prerequisites

  • Can you reproduce the problem in a MWE?
  • Are you running the latest version of AngleSharp?
  • Did you check the FAQs to see if that helps you?
  • Are you reporting to the correct repository? (there are multiple AngleSharp libraries, e.g., AngleSharp.Css for CSS support)
  • Did you perform a search in the issues?

For more information, see the CONTRIBUTING guide.

Possible Solution

I unfortunately dont have the raw HTML that caused this issue but i have confirmed the following change does fix the issue.

            rules.Where(m => m.Selector?.Match(element) ?? false).OrderBy(m => m.Selector.Specificity);

Would you accept a PR for this solution?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions