csswg-drafts icon indicating copy to clipboard operation
csswg-drafts copied to clipboard

[css-values-3] attribute reference attr() length with a '0' value

Open TalbotG opened this issue 4 years ago • 5 comments
trafficstars

This issue was triggered by the examination of attr-length-valid-zero-nofallback.html test in which the relevant code is

#outer2 { width: 200px; width: attr(data-test length); height: 200px; }
(...)
<div id="outer2" data-test="0"></div>

The spec states " The attribute value must parse as a <dimension-token>, and be successfully interpreted as the specified type. (...) " https://www.w3.org/TR/css-values-3/#ref-for-valdef-type-or-value-length

and

" (...) <dimension-token> additionally have a unit composed of one or more code points. " https://www.w3.org/TR/css-syntax-3/#typedef-dimension-token

Based on that alone, I believe that the attr-length-valid-zero-nofallback.html test is incorrect.

The spec needs to be clear or become clearer for similar code scenarios where the 0 value is used without unit for length, angle, time, frequency

The test also contradicts and collides with the comments made in attr-invalid-type-002.html test where the relevant code is the same and where we can read

#outer { width: 200px; width: attr(data-test number); height: 200px; } /* NOTE: while '0' is a valid length AND a valid number, the number type isn't a valid representation of a length. */ /* The reason for this is that most numbers aren't valid length */ /* ! Spec need some updates to make those assumptions clearly valid (see Tab Atkins for details) */ (...) <div id="outer" data-test="0"></div>

TalbotG avatar Apr 26 '21 22:04 TalbotG

@FremyCompany

TalbotG avatar Apr 26 '21 22:04 TalbotG

Mmm, your comments make sense to me, @TalbotG. I am totally fine with someone deleting my old test, given the explicit comment in the other test.

But as mentioned in that test, the spec should probably mention this explicitly if that isn't the case already.

FremyCompany avatar Apr 27 '21 11:04 FremyCompany

I think the spec does not mention this explicitly or clearly. Some explanations with an example would be appropriate.

TalbotG avatar Apr 27 '21 12:04 TalbotG

Oops... It's not exactly the same!

The attr-length-valid-zero-nofallback.html test uses

width: attr(data-test length);

while the attr-invalid-type-002.html test uses

width: attr(data-test number);

Nevertheless, this issue remains valid. The '0' code scenario in cases where an attribute length is expected should be clarified with an example and explanations.

TalbotG avatar Apr 27 '21 18:04 TalbotG

In §5 Distance Units: the <length> type, we can read " For zero lengths the unit identifier is optional (i.e. can be syntactically represented as the <number> '0'). However, if a '0' could be parsed as either a <number> or a <length> in a property (such as line-height), it must parse as a <number>. "

In §8.2 Attribute References: attr() we can read " The optional <type-or-unit> argument is a keyword drawn from the list below that tells the UA how to interpret the attribute value "

If all this is coherent and consequent, then I think that attr-length-valid-zero-nofallback.html test is incorrect while attr-invalid-type-002.html test is correct.

TalbotG avatar Apr 29 '21 17:04 TalbotG