Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clamp alpha during parse, other tweaks #119

Merged
merged 1 commit into from
Jan 2, 2025

Conversation

waywardmonkeys
Copy link
Collaborator

  • § 4.2 of the CSS Color 4 spec states that the parsed alpha value will be clamped.
  • Add a new enum Mode to help indicate whether we're in modern or legacy parsing mode. This can be used in additional ways in subsequent commits to improve the strictness of parsing.
  • Reading an alpha value no longer automatically consumes trailing white space.

@waywardmonkeys waywardmonkeys added this to the 0.2.2 milestone Jan 1, 2025
@waywardmonkeys
Copy link
Collaborator Author

FWIW, I found this running some of the CSS tests from Simon Sapin.

Copy link
Contributor

@raphlinus raphlinus left a comment

Choose a reason for hiding this comment

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

Yes, this is more correct. Thanks!

I'm seeing where I went wrong. The language for rgb() says "Values outside these ranges are not invalid, but are clamped to the ranges defined here at parsed-value time." so I applied the alpha clamping there, but missed the broader statement in 4.2. Good catch, and a good argument for tests.

color/src/parse.rs Show resolved Hide resolved
color/src/parse.rs Show resolved Hide resolved
* § 4.2 of the CSS Color 4 spec states that the parsed alpha
  value will be clamped.
* Add a new enum `Mode` to help indicate whether we're in
  modern or legacy parsing mode. This can be used in additional
  ways in subsequent commits to improve the strictness of parsing.
* Reading an alpha value no longer automatically consumes trailing
  white space.
@waywardmonkeys waywardmonkeys added this pull request to the merge queue Jan 2, 2025
Merged via the queue into linebender:main with commit adde938 Jan 2, 2025
16 checks passed
@waywardmonkeys waywardmonkeys deleted the fix-alpha-clamping branch January 2, 2025 18:17
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.

2 participants