-
Notifications
You must be signed in to change notification settings - Fork 707
[css-counter-styles] Additive algorithm shouldn't divide by 0 #5784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Should we just skip over 0-weight entries, or call them invalid? This is an integer, so it's fine for us to define the range as [1,Inf]. I'm inclined to do the latter, unless there's a great reason to do otherwise (and unless there's web compat or impl difficulties, 'we're currently doing the first one' isn't a sufficient reason, imo). |
It may make sense to make a lone 0-weight entry invalid. But not in general, I think it's reasonable to be able to specify a custom symbol for zero in: <style>
@counter-style dice {
system: additive;
additive-symbols: 6 ⚅, 5 ⚄, 4 ⚃, 3 ⚂, 2 ⚁, 1 ⚀, 0 ∅;
suffix: " ";
range: infinite infinite;
}
</style>
<ol start="-12" style="list-style: dice"></ol>
<script>
for (let i = -12; i <= 12; ++i)
document.querySelector("ol").append(document.createElement("li"));
</script> |
...sigh, yes, apologies, I forget how my own spec works. A zero entry is indeed necessary, just not by itself. Okay, I'll fix the spec, thanks for bearing with me. ^_^ |
All right, rewrote the algo a little for style purposes, and fixed the bug. A zero-weight tuple is now just skipped over. (And I now early-exit when 'value' hits 0, so since a 0-weight tuple must be the last one encountered in a valid 'additive-symbols', if you hit it you're in fallback territory, and now properly fall into that step.) |
Thanks, mostly it looks good, but the final assertion may not hold: <style>
@counter-style foo {
system: additive;
additive-symbols: 1 ⚀;
}
</style>
<li value="0" style="list-style: foo inside"></li>
It's 0.
The condition is false because there is no tuple with a weight of 0. So we start the loop
Assert failed, the value is zero. |
I guess you can remove the "or weight is greater than value" condition. If |
Fair, I'd hoped it would make it clearer, but it does indeed trip the assert. ^_^ |
…cally necessary, and it trips the assert. #5784
Ah, no, sorry, my suggestion was wrong! Because in the example above, we want to use the fallback style to display zero, instead of using an empty string. |
Ah, indeed, my brain isn't working great this morning either. Okay, I'm now just catching the zero-value case right away and either rendering it or triggering fallback. Then the non-zero values get to fall thru to the rest of the algo. |
Seems good now, thanks |
Actually, maybe it's not crystal clear that the steps are aborted at 2.2? Consider something like
|
Not sure if I'm missing something, but consider
From https://drafts.csswg.org/css-counter-styles/#additive-system
It's 1, so no-op.
Fine, value = 1 > 0 and the symbol list contains one additive tuple.
The current tuple is
0 ⚀
.floor(1 / 0) = floor(∞) = ∞
. So the algorithm is asking to append⚀
infinite times??value = 1 - 0*∞ = 1 - NaN = NaN
, I guess?NaN is not greater than 0, presumably.
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.
The text was updated successfully, but these errors were encountered: