Skip to content

fix: handle null inline style declarations in style attribute comparers#59

Open
SimonCropp wants to merge 1 commit into
AngleSharp:develfrom
SimonCropp:fix-handle-null-inline-style-declarations-in-style-attribute-comparers
Open

fix: handle null inline style declarations in style attribute comparers#59
SimonCropp wants to merge 1 commit into
AngleSharp:develfrom
SimonCropp:fix-handle-null-inline-style-declarations-in-style-attribute-comparers

Conversation

@SimonCropp

Copy link
Copy Markdown

StyleAttributeComparer and OrderingStyleAttributeComparer passed the result of IElement.GetStyle() straight into CompareCssStyleDeclarations, which dereferences it. GetStyle() returns null when an element has no inline CSS style declaration to parse — a non-HTML (SVG/MathML) element, or any element when the browsing context has no ICssParser registered (e.g. consumers that don't call .WithCss(), such as bUnit). Comparing a styled element in that situation threw a NullReferenceException.

Both comparers now fall back to comparing the raw style attribute value when either declaration is null, so such elements compare by value instead of throwing.

Adds regression tests that build the comparison in a CSS-less browsing context, since the shared test fixture enables CSS and so cannot reproduce the issue.

StyleAttributeComparer and OrderingStyleAttributeComparer passed the result of
IElement.GetStyle() straight into CompareCssStyleDeclarations, which dereferences
it. GetStyle() returns null when an element has no inline CSS style declaration
to parse — a non-HTML (SVG/MathML) element, or any element when the browsing
context has no ICssParser registered (e.g. consumers that don't call .WithCss(),
such as bUnit). Comparing a styled element in that situation threw a
NullReferenceException.

Both comparers now fall back to comparing the raw style attribute value when
either declaration is null, so such elements compare by value instead of
throwing.

Adds regression tests that build the comparison in a CSS-less browsing context,
since the shared test fixture enables CSS and so cannot reproduce the issue.
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