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

AtkinsSJ has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-values-4] "Serialize a math function" step 4 behaves wrong for some node types ==
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](https://drafts.csswg.org/css-values-4/#serialize-a-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](https://infra.spec.whatwg.org/#string-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.

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/11783 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Wednesday, 26 February 2025 14:55:11 UTC