Skip to content

Accept the CSS-wide keywords for any property - #86

Open
Madin-H23 wants to merge 1 commit into
jaraco:mainfrom
Madin-H23:fix/accept-css-wide-keywords
Open

Madin-H23 wants to merge 1 commit into
jaraco:mainfrom
Madin-H23:fix/accept-css-wide-keywords

Conversation

@Madin-H23

Copy link
Copy Markdown

Fixes #19.

cssutils.profile.validate('color', 'unset') is False on main, while inherit is accepted:

>>> cssutils.profile.validate('color', 'inherit')
True
>>> cssutils.profile.validate('color', 'unset')
False

The values are validated against the profile regexes, and the CSS-wide keywords only appear in the regexes where they were spelled out per property, so a value such as unset was reported as invalid.

CSS Values 4 defines initial, inherit, unset and revert as valid in place of the value of any property, so this change adds them where the property regexes are compiled:

CSS_WIDE_KEYWORDS = 'inherit|initial|unset|revert'

The per-property definitions are left untouched, and only those four keywords are added, so invalid values stay invalid.

One existing expectation changes as a consequence: an @font-face descriptor rejecting inherit (font-style: inherit) is now valid, since the CSS-wide keywords apply to any property. If you would rather keep the font-face profile strict, say so and I will scope the change.

Verified locally:

  • pytest: 625 passed, 43 xfailed
  • ruff check and ruff format --check (ruff 0.17.1): clean
  • mypy --config-file mypy.ini cssutils: no new findings (the 40 reported errors are pre-existing on main)

🤖 This contribution was drafted with AI assistance; the analysis, the change and the tests are described above so that they can be reviewed.

The property values are validated against the profile regexes, and the
CSS-wide keywords were only present in the regexes where they had been
spelled out per property, so a value such as "unset" was reported as
invalid.

CSS Values 4 defines initial, inherit, unset and revert as valid in
place of the value of any property, so add them where the property
regexes are compiled.
@Madin-H23

Copy link
Copy Markdown
Author

The tests workflow on this fork PR is waiting in action_required (the first-time-contributor approval that fork PRs need). Could you approve it so the CI runs?

The change is small, and here is the local verification:

  • pytest: 625 passed, 43 xfailed
  • ruff check and ruff format --check (ruff 0.17.1): clean
  • mypy --config-file mypy.ini cssutils: no new findings (the 40 reported errors are pre-existing on main)

The regression is reproducible on main alone: with the tests of this branch applied to the unpatched sources, test_css_wide_keywords fails, because cssutils.profile.validate('color', 'unset') is False there.

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.

Property Color unset invalid value

1 participant