Skip to content

Fix/css inherit shorthand resolution#203

Merged
FlorianRappl merged 1 commit intoAngleSharp:develfrom
jafin:fix/css-inherit-shorthand-resolution
Mar 27, 2026
Merged

Fix/css inherit shorthand resolution#203
FlorianRappl merged 1 commit intoAngleSharp:develfrom
jafin:fix/css-inherit-shorthand-resolution

Conversation

@jafin
Copy link
Copy Markdown
Contributor

@jafin jafin commented Mar 27, 2026

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

Fix CSS inherit keyword not resolving on shorthand properties

The inherit keyword on shorthand properties like border, margin,
and padding was not correctly resolved to parent values. Three
independent bugs contributed:

  1. DeclarationInfo: shorthand converters with null InitialValue were
    not wrapped with StandardValueConverter, so CSS-wide keywords like
    inherit were either ignored or partially mis-parsed by the
    property-specific converter. Fixed by always wrapping with
    StandardValueConverter first.

  2. DeclarationInfoExtensions.Expand: CssInheritValue and CssUnsetValue
    were not handled when expanding shorthand properties to longhands,
    causing them to fall through to the aggregator Split which returned
    null. Added explicit handling for both value types.

  3. DeclarationInfoExtensions.Collapse: CssInheritValue was not tracked
    for round-trip serialization of shorthand properties. Added inherit
    tracking alongside initial, unset, and child.

  4. CssStyleDeclaration.ChangeDeclarations: when UpdateDeclarations
    found a child property with explicit inherit value, it removed it
    but did not allow the parent value to replace it because the skip
    flag was not reset. Fixed by setting skip to false when the old
    declaration is removed.

fixes #184

@jafin jafin marked this pull request as draft March 27, 2026 12:35
The `inherit` keyword on shorthand properties like `border`, `margin`,
and `padding` was not correctly resolved to parent values. Three
independent bugs contributed:

1. DeclarationInfo: shorthand converters with null InitialValue were
   not wrapped with StandardValueConverter, so CSS-wide keywords like
   `inherit` were either ignored or partially mis-parsed by the
   property-specific converter. Fixed by always wrapping with
   StandardValueConverter first.

2. DeclarationInfoExtensions.Expand: CssInheritValue and CssUnsetValue
   were not handled when expanding shorthand properties to longhands,
   causing them to fall through to the aggregator Split which returned
   null. Added explicit handling for both value types.

3. DeclarationInfoExtensions.Collapse: CssInheritValue was not tracked
   for round-trip serialization of shorthand properties. Added inherit
   tracking alongside initial, unset, and child.

4. CssStyleDeclaration.ChangeDeclarations: when UpdateDeclarations
   found a child property with explicit `inherit` value, it removed it
   but did not allow the parent value to replace it because the skip
   flag was not reset. Fixed by setting skip to false when the old
   declaration is removed.
@jafin jafin force-pushed the fix/css-inherit-shorthand-resolution branch from 78b073e to 56102e0 Compare March 27, 2026 12:48
@jafin jafin marked this pull request as ready for review March 27, 2026 12:51
@FlorianRappl FlorianRappl added this to the v1.0 milestone Mar 27, 2026
Copy link
Copy Markdown
Contributor

@FlorianRappl FlorianRappl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks!

@FlorianRappl FlorianRappl merged commit cc364f5 into AngleSharp:devel Mar 27, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Overriding inheritance not working?

2 participants