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

[css-values-4] "Serialize a math function" step 4 behaves wrong for some node types #11783

Open
AtkinsSJ opened this issue Feb 26, 2025 · 0 comments

Comments

@AtkinsSJ
Copy link
Contributor

https://drafts.csswg.org/css-values-4/#serialize-a-math-function

Step 4 says:

For each child of the root node, serialize the calculation tree. If a result of this serialization starts with a "(" (open parenthesis) and ends with a ")" (close parenthesis), remove those characters from the result. Concatenate all of the results using ", " (comma followed by space), then append the result to s.

There are a couple of issues with this:

  1. The clamp() function has a <rounding-strategy> as its first child. Passing that to "serialize the calculation tree" isn't valid, but ignoring it would miss it from the serialization.
  2. If root is a numeric value and we are serializing it before the computed-value stage, it has no children and should be passed to "serialize the calculation tree" directly.
  3. If root is a calc-operator node, serializing its children as a comma-separated list is incorrect. It should also be passed to "serialize the calculation tree" directly.

When implementing this in Ladybird, I replaced step 4 with this behaviour, and it seems to be correct according to the WPT tests I've checked:

  • If the root node is a numeric value, or a calc-operator node:
    • Call "serialize the calculation tree" on the root node, then any wrapping (), and append that to s.
  • Otherwise:
    • If the root node is a Clamp function:
      • Serialize its rounding-strategy and append that to s, followed by ", ".
    • Perform the original step 4 on the children that are calculation nodes.

In reality you'd want to combine that with step 3, as the two steps have identical if conditions.

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

No branches or pull requests

1 participant