Skip to content

Fix NullReferenceException comparing markup with style attributes#110

Merged
SimonCropp merged 1 commit into
mainfrom
Fix-NullReferenceException-comparing-markup-with-style-attributes
Jul 3, 2026
Merged

Fix NullReferenceException comparing markup with style attributes#110
SimonCropp merged 1 commit into
mainfrom
Fix-NullReferenceException-comparing-markup-with-style-attributes

Conversation

@SimonCropp

Copy link
Copy Markdown
Member

Fix NullReferenceException comparing markup with style attributes

BunitMarkupComparer parsed markup with a CSS-unaware HtmlParser, so an element's inline style parsed to a null ICssStyleDeclaration. AngleSharp .Diffing's StyleAttributeComparer compares style attributes semantically, so it dereferenced that null and threw the moment two style attributes differed — surfacing as an NRE instead of a diff on any HTML snapshot whose elements carry differing styles.

Parse through a CSS-enabled configuration (Configuration.Default.WithCss()) so every element gets a real CSS object model and the style comparison works. AngleSharp.Css is already present transitively via bunit.

Add a regression test covering two markup strings that differ only in style-attribute whitespace, which forces the comparer through the CSS parse that previously crashed.

Fix NullReferenceException comparing markup with style attributes

BunitMarkupComparer parsed markup with a CSS-unaware HtmlParser, so an
element's inline style parsed to a null ICssStyleDeclaration. AngleSharp
.Diffing's StyleAttributeComparer compares style attributes semantically,
so it dereferenced that null and threw the moment two style attributes
differed — surfacing as an NRE instead of a diff on any HTML snapshot
whose elements carry differing styles.

Parse through a CSS-enabled configuration (Configuration.Default.WithCss())
so every element gets a real CSS object model and the style comparison
works. AngleSharp.Css is already present transitively via bunit.

Add a regression test covering two markup strings that differ only in
style-attribute whitespace, which forces the comparer through the CSS
parse that previously crashed.
@SimonCropp SimonCropp added this to the 13.0.4 milestone Jul 3, 2026
@SimonCropp SimonCropp merged commit c59812d into main Jul 3, 2026
3 of 5 checks passed
@SimonCropp SimonCropp deleted the Fix-NullReferenceException-comparing-markup-with-style-attributes branch July 3, 2026 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant