Skip to content

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

Open
@AtkinsSJ

Description

@AtkinsSJ

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions