Skip to content

Release 1.3.1 - #259

Merged
FlorianRappl merged 7 commits into
mainfrom
devel
Nov 1, 2026
Merged

FlorianRappl merged 7 commits into
mainfrom
devel

Conversation

@FlorianRappl

Copy link
Copy Markdown
Contributor

Types of Changes

Prerequisites

Please make sure you can check the following two boxes:

  • I have read the CONTRIBUTING document
  • My code follows the code style of this project

Contribution Type

What types of changes does your code introduce? Put an x in all the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue, please reference the issue id)
  • New feature (non-breaking change which adds functionality, make sure to open an associated issue first)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed

Description

This pull request introduces several important improvements and updates for the AngleSharp.Css library, focusing on enhanced parser safety, modern dependency support, trimming and Native AOT compatibility, and improved test coverage. It also updates documentation and CI workflows to reflect these changes.

These changes collectively improve the reliability, maintainability, and modern .NET compatibility of the library.

FlorianRappl and others added 7 commits October 31, 2026 19:10
- Require AngleSharp 1.9.0 (csproj default and CI), which the trim-safe
  ToDictionary<T> below needs
- Mark the net8.0 and net10.0 targets IsAotCompatible, so the trim and AOT
  analyzers run on every build, with the same KnownILLinkPack override as
  AngleSharp and AngleSharp.Xml
- Add a generic Css<T, TProperties> overload whose type parameter is
  annotated so the trimmer keeps its public properties. The Object overload
  stays, marked Obsolete and RequiresUnreferencedCode, so code compiled
  against it keeps working; on a recompile a call with an anonymous object
  binds to the generic overload, and a dictionary is copied rather than
  reflected over
- Add internal copies of DynamicallyAccessedMembersAttribute and
  RequiresUnreferencedCodeAttribute for the targets whose BCL predates them
- Add tests for Css with an anonymous object, a dictionary and a value
  declared as Object
- Update AGENTS.md

The package keeps its target frameworks and its dependencies apart from the
AngleSharp minimum. Apps on net462, net472, net6.0, net7.0, net8.0 and
net10.0 and a netstandard2.0 library build against the packed package
without warnings and run correctly, and a console app published with
PublishAot compiles with no trim or AOT warnings.
A style sheet nesting blocks deeply ended the process with a stack overflow,
which no caller can catch: the parser recurses once per level of @media,
@supports, @layer, @container, @scope and nested style rules. On a 256 KB
thread stack, about 125 nested @media rules were enough (.NET 8, before the
JIT optimizes); on a 1 MB stack about 580.

- Add CssParserOptions.MaxNestingDepth (default 64). A rule nested in more
  blocks is dropped like an invalid rule, raising the new
  CssParseError.NestingTooDeep, and parsing continues after it
- Add tests at depths that crashed before and at the limit, parsing on a
  256 KB thread stack; with a default of 128 the test host crashes
- Add a benchmark parsing nested @media and nested style rules

This is a mitigation, not a fix: parsing still recurses once per level, and
only the limit stops it. Raising the limit brings the crash back.
Adopt AngleSharp 1.9 and make the library trim and Native AOT compatible
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants