[css-counter-styles] Additive algorithm shouldn't divide by 0 · Issue #5784 · w3c/csswg-drafts (original) (raw)
Not sure if I'm missing something, but consider
From https://drafts.csswg.org/css-counter-styles/#additive-system
- If value is initially 0
It's 1, so no-op.
- While value is greater than 0 and there are elements left in the symbol list:
Fine, value = 1 > 0 and the symbol list contains one additive tuple.
2.1. Pop the first additive tuple from the symbol list. This is the current tuple.
The current tuple is 0 ⚀
.
2.2. Append the current tuple’s counter symbol to S
floor( value / current tuple’s weight )
times (this may be 0).
floor(1 / 0) = floor(∞) = ∞
. So the algorithm is asking to append ⚀
infinite times??
2.3 Decrement value by the _current tuple_’s weight multiplied by the number of times the current tuple was appended to S in the previous step.
value = 1 - 0*∞ = 1 - NaN = NaN
, I guess?
- While value is greater than 0
NaN is not greater than 0, presumably.
- If the loop ended because value is 0, return S. Otherwise, the given counter value cannot be represented by this counter style, and must instead be represented by the fallback counter style.
So I guess it may end up being fine with the fallback counter style. But it just seems pretty wrong for the algorithm to have divisions by 0, infinite insertions, etc.
Both Firefox and Chromium stop iterating if the weight is 0 . I think the algorithm should have that check too.