Skip to content

[css-values-5] Clarify how <attr-unit> should be parsed #12479

@AtkinsSJ

Description

@AtkinsSJ

The spec for this says:

If given as an <attr-unit> value, the value is first parsed as if type(<number>) was specified, then the resulting numeric value is turned into a dimension with the corresponding unit, or a percentage if % was given. Values that fail to parse as a <number> trigger fallback.

<number> can mean a literal number, but it can also be a math function, or various other functions that produce <number>. Chromium added a crash test which checks that a non-literal appearing doesn't break the browser:

<!DOCTYPE html>
<link rel="help" href="https://crbug.com/405422528">
<div data-crash="sibling-index()" style="width: attr(data-crash px)"></div>
<div data-crash="sign(1em - 1px)" style="width: attr(data-crash px)"></div>

But their fix assumes that only <number> literals are allowed.

The spec is ambiguous here. Only allowing literals is one interpretation (and certainly the easiest to implement!) but the other interpretation (which I read the spec as meaning) is that this:

<div data-crash="sign(1em - 1px)" style="width: attr(data-crash px)"></div>

...should produce a width value equivalent to calc(sign(1em - 1px) * 1px).

cc: @lilles

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Regular agenda

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions